[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] counting with position()


Subject: Re: [xsl] counting with position()
From: Syd Bauman <Syd_Bauman@xxxxxxxxx>
Date: Tue, 5 Jan 2010 15:52:17 -0500

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