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

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

Subject: Re: [xsl] How do I set up a counter or sequence number variable
From: "Wolfgang Laun wolfgang.laun@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 4 Nov 2014 11:13:16 -0000

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;'"/>

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;'"/>

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


On 3 November 2014 22:56, Catherine Wilbur cwilbur@xxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

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

Current Thread