Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Need help with count expression

From: "G. Ken Holman" <gkholman@-------------------->
To:
Date: 1/1/2009 3:42:00 AM
At 2008-12-31 12:47 -0800, Kit Strong wrote:
I need a bit of help with count() as so far I've
been unable to construct a valid expression to obtain what  I need
Basically
what I'm trying to do is generate Table numbers relative to Chapters but only
for tables that contain a title element.  Here's an example
structure


<chapter>
    <p>...</p>
    <table
class="topic/table">
        <title class="table/title">(should
resolve to Table 1.1) ...<title>
        ...

</table>
     <table class="topic/table>...</table>

<section>
       <table> ...</table>

<table>
            <title class="table/title">(should resolve to
Table 1.2) ...<title>
            ...
        </table>
    </chapter>
<chapter>
    <table
class="topic/table>>...</table>
    <section>

<p>
            <table class="topic/table">

<title class="table/title">Should resolve to Table 2.1
</title>
                ...
            </table>

</p>
    </section>
</chapter>

Getting the

chapter number is easy enough 'count(preceding::chapter)+1' but what 
I'm having

problems with is the Table number in relation to the chapter

I can get the

Table position in relation to the document

via

select="count(preceding::*[contains(@class,' topic/table

')]/*[contains(@class,' topic/title ')])+1"

but I'm not quite sure how to

combine the 2 expressions to give me the proper count in relationship to the

current <chapter>



Any help would be much appreciated.

I think you should just use what you need along the lines of the following:



   <xsl:number count="*[contains(@class,' topic/table ')]
                      [*[contains(@class,' topic/title ')]]"
               from="chapter" level="any"/>

... instead of using count().  The from= limits the count to those 
items below the closest matching ancestor.



Note also that I'm counting tables qualified by their title ... in 
your code you were counting the table titles.  Probably the same in 
this case, but semantically I'm counting tables in case that helps 
for maintenance and understanding.



I hope this helps.



. . . . . . . . . . . Ken



--
Upcoming XSLT/XSL-FO, UBL and code list hands-on training classes:
:  Sydney, AU 2009-01/02; Brussels, BE 2009-03; Prague, CZ 2009-03
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent