[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Using number in an expression
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|