This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Using number in an expression
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "Rick Quatro" <rick at frameexpert dot com>
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Mon, 25 Feb 2002 13:25:45 +0000
- Subject: Re: [xsl] Using number in an expression
- Organization: Jeni Tennison Consulting Ltd
- References: <006901c1be00$cdd43b00$4c744242@rochester.rr.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
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