[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Using number in an expression

Subject: Re: Using number in an expression
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 25 Feb 2002 13:25:45 +0000
expressions using number 13
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.