Re: [xsl] problem with proper numbering

Subject: Re: [xsl] problem with proper numbering
From: Joerg Pietschmann <joerg.pietschmann@xxxxxx>
Date: Tue, 02 Oct 2001 18:51:14 +0200
"Andreas Putscher" <andreasputscher@xxxxxx> wrote
> Hi everybody,
[...]
> So I would like to transform "slidesets" and "slides" into "cards". The
> problem I have is concerned with the numbering of the "cards".
[...]
> So the position() function does not work in here as it starts numbering the
> card-id with "a" again and again
That's how position() works, by design. Look it up in the spec.

>, but what I want is strictly ascending numbering of the id.

The default answers are:
a) Use <xsl:number count="slideset|slide" level="any" format="a"/>
b) Use "count(preceding::slideset|preceding::slide)" instead of "position()"
c) Use <card id="{generate-id()}"> ... instead of
   <card>
     <xsl:attribute name="id"><xsl:number ...></xsl:attribute>
     ...
The last possibility uses a shortcut called attribute value template
instead of the more verbose <xsl:attribute> you used.
As a rule of thumb, c) should be faster than a) which in turn should
be noticable faster than b), however, generate-id() generates usually
strings of several characters, which might matter in the case of
generating WML.

See http://www.w3c.org/TR/xslt#number, http://www.w3.org/TR/xpath#axes,
http://www.w3.org/TR/xpath#section-Node-Set-Functions and
http://www.w3c.org/TR/xslt#misc-func

Untested, try it out by yourself. HTH anyway
J.Pietschmann

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread