Click to See Complete Forum and Search --> : Autoincrementing column in XSL file


XMLNewbie
05-03-2003, 12:20 AM
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>
<xsl:otherwise>#E0DFE3</xsl:otherwise>
</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>

khalidali63
05-03-2003, 07:25 AM
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/javascripts/xmlstuff/xmlfiles/DOMXMLParsing.xml

sheila
05-03-2003, 07:43 AM
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>

XMLNewbie
05-03-2003, 09:02 AM
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!

khalidali63
05-03-2003, 10:14 AM
great..Shiela.I misundersttod the quest..:D

sheila
05-03-2003, 10:29 AM
I don't think so. In fact I'll be using your discovery myself!