This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]