[xsl] Identifying alternate rows.

Subject: [xsl] Identifying alternate rows.
From: Jitu <jibhatia@xxxxxxxxxxx>
Date: Wed, 11 Dec 2002 15:00:22 +0530
I have a xml file of the nature :
<row>
       <firstname> James <firstname>
      <lastname> Gosling <lastname>
      <nickname> Jame <nickname>
</row>
<row>
       <firstname> John <firstname>
      <lastname> Green <lastname>
      <nickname> Greeny <nickname>
</row>
<row>
       <firstname> Rojer <firstname>
      <lastname> Gee <lastname>
      <nickname> Roj <nickname>
</row>

I will be displaying this in a table format using XSL and output is HTML.

For this i am using xsl:for loop and outputting data.
I need to highlight alternating rows.

My problem is that in xsl i cannot change value of a variable once declared (based on my limited experience with xsl). So i cannot declare a variable and then keep incrementing it in my for loop, and then figure out if it is has a odd number value or not inside the loop. Every odd number value can indicate to me that the row has to be highlighted.

Here is what xsl for my for loop would look like (I hope i have written it correctly here...):
...
<table>
<xsl:for-each select="row">
<tr> <!-- For every odd numbered row instead of <tr> i would output <tr bgcolor='green'> -->
<td> <xsl:value-of select="firstname" /></td>
<td> <xsl:value-of select="lastname" /></td>
<td> <xsl:value-of select="nickname" /></td>
</tr>
</xsl:for-each>
</table>
...


I am trying to generate a typical report which will have hundreds of rows. Every alternate row must be colored differently.

How can i achieve this.

Thanks for your help


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread