RE: [xsl] counter in XSL - some more info ... help still needed

Subject: RE: [xsl] counter in XSL - some more info ... help still needed
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 04 Dec 2003 09:01:33 -0500
At 2003-12-04 13:21 +0100, Sebastian Fey wrote:
the documentation consists of several docbook-xml-documents, each document is part of a class.
lets call them classA and classB. documents can also be part of both classes (classALL)

the class is stored in an attribute in the docbook-xml-documents

<book type="classX" ...>

the structure of the release is described in release.xml:

<book fileref="{uri of book1} /><!--assume book1 has classA-->
<book fileref="{uri of book2} /><!--assume book2 has classB-->
<book fileref="{uri of book3} /><!--assume book3 has classALL-->
<book fileref="{uri of book4} /><!--assume book4 has classA-->
<book fileref="{uri of book5} /><!--assume book5 has classALL-->
titlepage for classB would look like this:

Volume 1. Installation
1. book2/title
2. book3/title
3. book5/title
the problem is obvious, eg book5 has the label "3." but its the 5th child of volume.
so I cant use position() and xsl:number.

Who says you cannot use xsl:number? This is what it is there for. It looks like you want to count those books whose referenced book type is either 'classB' or 'classAll'. If I've understood your needs correctly, then just count the things you need by describing the nodes that need to be counted (let the XSLT processor do the heavy lifting):

<xsl:number count="book[document(@fileref)/book/@type='classB' or

I need sth like a counter to solve this problem ...

If you really want to use a counter then you'll have to use another environment because XSLT does not provide anything with which to implement counters except, perhaps, complex recursive calls maintaining passed numeric variables where on the innermost loop you effect the desired result based on the incremented value. In my XSLT teaching I see students who are programmers coming to my class after attempting to solve these kinds of problems in programming approaches that are not at all necessary for most of the counting requirements. These contorted solutions have all, so far, been replaced with one-instruction solutions.

If you want to use XSLT then you'll have to use the facilities that are provided for you, and the designers have given us a lot of power in this area.

I hope this helps.

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

-- Next public European delivery: 3-day XSLT/2-day XSL-FO 2004-01-?? Instructor-led on-site corporate, government & user group training for XSLT and XSL-FO world-wide: please contact us for the details

G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                       Definitive XSLT and XPath
ISBN 0-13-140374-5                               Definitive XSL-FO
ISBN 1-894049-08-X   Practical Transformation Using XSLT and XPath
ISBN 1-894049-11-X               Practical Formatting Using XSL-FO
Member of the XML Guild of Practitioners:
Male Breast Cancer Awareness

XSL-List info and archive:

Current Thread