www.webdeveloper.com
Results 1 to 6 of 6

Thread: Autoincrementing column in XSL file

  1. #1
    Join Date
    May 2003
    Posts
    8

    Autoincrementing column in XSL file

    Hi:

    I am trying to autoincrement the column named "order".
    Starting at 1 and stepping 1 for each row.

    Any suggestions would be appreciated.

    Chuck

    <xsl:template match="contact">
    <tr>
    <xsl:attribute name="bgcolor">
    <xsl:choose>
    <xsl:when test="position() mod 2 = 1">#F0F1F5</xsl:when>
    <xsltherwise>#E0DFE3</xsltherwise>
    </xsl:choose>
    </xsl:attribute>
    <td align="center">
    <INPUT maxLength="2" name="order" size="2" value="1"/>
    </td>
    <td align="center">
    <INPUT maxLength="30" name="name" size="30" value="{con_nam}"/>
    </td>
    <td align="center">
    <INPUT maxLength="12" name="priphone" size="12" value="{con_phone1}"/>
    </td>
    <td align="center">
    <INPUT maxLength="12" name="altphone" size="12" value="{con_phone2}"/>
    </td>
    <td align="center">
    <INPUT maxLength="12" name="relationship" size="12" value="{con_relation}"/>
    </td>
    <td align="center">
    <INPUT maxLength="34" name="comments" size="26" value="{con_comment}"/>
    </td>
    </tr>
    </xsl:template>
    </xsl:stylesheet>

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    2,653
    XSL is a steteless language,My recomendation for you is save yourself tonnes of hours figuring the incrementation out and just when the page is loaded run javascript with some DOM methods to update the names that match value order.

    Here is an example of such doing...
    http://68.145.35.86/skills/javascrip...XMLParsing.xml

  3. #3
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    95
    I think this should work:

    <xsl:template match="contact">
    <xsl:variable name="position" select="position()" />
    <tr>
    <td align="center">
    <INPUT maxLength="2" name="order" size="2" value="{$position}"/>
    </td>
    etc...
    </tr>
    </xsl:template>

  4. #4
    Join Date
    May 2003
    Posts
    8
    Hi Sheila!

    Great suggestion. It worked perfectly.

    I also found that this statement works after looking at your suggestion.

    <INPUT maxLength="2" name="order" size="2" value="{position()}"/>

    Without the <xsl:variable name="position" select="position()" /> statement.

    Is there any disadvantage in just having one statement instead of two?

    Have a great day!

  5. #5
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    2,653
    great..Shiela.I misundersttod the quest..

  6. #6
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    95
    I don't think so. In fact I'll be using your discovery myself!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles