Subject: Re: [xsl] Using number in an expression From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Mon, 25 Feb 2002 13:25:45 +0000 |
Hi Rick, > I am using <xsl:number/> to output the number of the current > element. I would like to add another number (99) to the value of > <xsl:number/>. > > I was using <xsl:value-of select="position()+99"/>, which worked > fine except it was counting sibling elements. <xsl:number/> counts > correctly, but I need to add the 99 to the result before outputting > it. Thanks in advance. The position() function actually gives you the position of the node amongst the set of nodes that you're processing at the moment. The xsl:number element gives you the position of the node amongst its siblings of the same type. So, say that you're numbering 'item' elements. What xsl:number gives you is equivalent to: <xsl:value-of select="count(preceding-sibling::item) + 1" /> To get the count from 100 (which is what you're trying to do by adding 99), you can do: <xsl:value-of select="count(preceding-sibling::item) + 100" /> For speed, if you can then you should try to use the position() function - counting preceding siblings takes time, and if you're doing it for lots of items, then it takes a great deal of time! Using the position() function is relatively efficient; but of course it means that you get the position within the list you're processing rather than the original source document, so it might not be practical. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Using number in an expression, Rick Quatro | Thread | [xsl] XSL nodes evaluation on the f, Ivanco Maros |
Re: [xsl] Using number in an expres, Oliver Becker | Date | [xsl] Using number in an expression, Rick Quatro |
Month |