Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vary background color for unkown number of table rows

Status
Not open for further replies.
Feb 7, 2007
7
US
I am currently doing an xsl:for-each statement to read part of an xml file that's being output into html and would like to alternate the background color for alternate table rows of data to make things easier to read on the user end.

As the number of rows of data varies, how would I go about doing this? I am looking into doing something with the count function now, but can't find info how to alternate the color based on odd or even numbers.

Any ideas?

Thank you in advance for any help.
 
Consider this inside your xsl:for-each:
Code:
<xsl:choose>
<xsl:when test="position() mod 2 = 0" 
<!-- even row color -->
</xsl:when>
<xsl:otherwise>
<!-- odd row color -->
</xsl:otherwise>
</xsl:choose>

Note that this can be extended to any number of row colors.

Tom Morrison
 
Nice! So you use the mod Xpath function (of which I hadn't heard before) to divide the position by 2, then if the remainder is 0 you get Color A and if it is 1 you get Color B.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top