xsl-list
[Top] [All Lists]

Re: [xsl] How do I set up a counter or sequence number variable

2014-11-04 05:13:31
In your first posting, there is a for-each over a sequence of nodes, and
one line is created for each item. You can number this (as Martin has
written - why didn't you follow up on his proposal?) by doing

    <xsl:template match="/">
        <xsl:for-each select="x/y/z/amount">
           <xsl:variable name="pos" select="position()"/>   <!-- position
within the for-each -->
           <!-- lots of other stuff omitted -->
          <xsl:value-of select="$pos, LIBPROD','&#xa;'"/>
        </xsl:for-each>
    </xsl:template>

If you match nodes by descending through the input document (using template
and apply-templates) you can also establish the ordinal of the currently
matched node, this time by calling index-of, e.g.

   <xsl:template match="amount">
     <xsl:variable name="pos" select="index-of( /x/y/z/amount, .)"/>
     <xsl:value-of select="$pos,.,'&#xa;'"/>
  </xsl:template>

BTW, both functions (position, index-of) would have turned up in prominent
positions after googling for "XSLT position within sequence".

Cheers
-W


On 3 November 2014 22:56, Catherine Wilbur cwilbur(_at_)uwindsor(_dot_)ca <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

 XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/528976> (by
email <>)

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>
  • Re: [xsl] How do I set up a counter or sequence number variable, Wolfgang Laun wolfgang(_dot_)laun(_at_)gmail(_dot_)com <=