[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Need help with count expression

Subject: Re: Need help with count expression
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 31 Dec 2008 22:30:51 -0500
Re:  Need help with count expression
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
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

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

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

       <table> ...</table>

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

            <table class="topic/table">

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


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
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

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.