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

Re: counting with position()

Subject: Re: counting with position()
From: Syd Bauman <Syd_Bauman@xxxxxxxxx>
Date: Tue, 5 Jan 2010 15:52:17 -0500
Re:  counting with position()
I think I'm missing something in your question, because my first
reaction is that

  <xsl:template match="level2/product">
    <xsl:message>I am product #<xsl:number/> in this level (2)</xsl:message>
  </xsl:template>

will do exactly what you ask:
> How do I count all the product elements and display until the last one?

Although I'm interpreting "until the last" to be inclusive. If you
want to exclude the last, you could use

  <xsl:template match="level2/product">
    <xsl:variable name="myPos" select="count(preceding-sibling::product) +1"/>
    <xsl:if test="count( ../product ) > $myPos">
      <xsl:message>I am product #<xsl:number/> in this level (2)</xsl:message>
    </xsl:if>
  </xsl:template>

Although I suspect there are better ways to do that.

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.