xsl-list
[Top] [All Lists]

Re: [xsl] counting with position()

2010-01-05 14:52:41
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.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--