XSLT incrementing count

Discussion in 'XML' started by John Wilkinson, Sep 5, 2005.

  1. Hi,
    I am new to XSLT. My problem is that I wish to create an HTML table, and
    give each row an incrementing number from 1.This would increment every
    itteration of a for-each loop.
    The XSLT fragment I have tried is:

    <xsl:variable name="test" select="0"></xsl:variable>
    <table border="1">
    <tbody>
    <tr bgcolor="#9acd32">
    <th>Number</th>
    </tr>
    <xsl:for-each select="amsal_coverage_stats/core">
    <tr>
    <td>

    <xsl:value-of select="$test+1"></xsl:value-of>

    </td>
    </tr>
    </xsl:for-each>

    However this just has the value 1.

    Any help would be much appreciated.

    Thanks.
    John.
    John Wilkinson, Sep 5, 2005
    #1
    1. Advertising

  2. John Wilkinson wrote:

    > My problem is that I wish to create an HTML table, and
    > give each row an incrementing number from 1.This would increment every
    > itteration of a for-each loop.


    > <xsl:for-each select="amsal_coverage_stats/core">
    > <tr>
    > <td>
    >
    > <xsl:value-of select="$test+1"></xsl:value-of>


    You can use
    <xsl:value-of select="position()" />

    For more advanced stuff you might want to check the <xsl:number> statement.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Sep 5, 2005
    #2
    1. Advertising

  3. John Wilkinson

    toudidel Guest

    don't use <xsl:for-each> element, it's terrible. Instead of it
    <xsl:apply-templates> with <xsl:value-of select="position()"/> in it.
    toudidel, Sep 6, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken
    Replies:
    2
    Views:
    19,249
  2. Miel Bronneberg

    xslt count error

    Miel Bronneberg, Oct 24, 2003, in forum: XML
    Replies:
    2
    Views:
    1,371
    Miel Bronneberg
    Oct 24, 2003
  3. Marcel Akkerman
    Replies:
    5
    Views:
    850
    Marcel Akkerman
    Feb 22, 2004
  4. bthumber

    Incrementing a count

    bthumber, May 29, 2009, in forum: ASP .Net
    Replies:
    1
    Views:
    369
    Alexey Smirnov
    May 29, 2009
  5. efelnavarro09
    Replies:
    2
    Views:
    900
    efelnavarro09
    Jan 26, 2011
Loading...

Share This Page