|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: alternating table background colour in an for-each
Michael,
You may have found a solution now. I began a reply earlier, but got
side-tracked by work!!!
Basically you can change the colours of rows by using the position()
function and mod
(mod being an math term which gives the remainder if a division. ie. 13 mod
4 would be 1. 13 can be divided by 4 three times and leaves a remainder of
1.)
An example is shown below, using a CSS.
<xsl:template match="products">
<xsl:choose>
<xsl:when test="position() mod 4 = 0">
<tr class="red">
<xsl:call-template name="showproducts" />
</tr>
</xsl:when>
<xsl:when test="position() mod 4 = 1">
<tr class="green">
<xsl:call-template name="showproducts" />
</tr>
</xsl:when>
<xsl:when test="position() mod 4 = 2">
<tr class="blue">
<xsl:call-template name="showproducts" />
</tr>
</xsl:when>
<xsl:when test="position() mod 4 = 3">
<tr class="pink">
<xsl:call-template name="showproducts" />
</tr>
</xsl:when>
</xsl:choose>
</xsl:template>
Hope that that provides enough info to go on,
Cheers, Tim Watts :)
-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Michael
Bauerfeld
Sent: Thursday, 19 July 2001 11:31 AM
To: xsl list
Subject: alternating table background colour in an for-each 'loop'
Hi everyone,
I'm trying to alternate the background colour of table rows (e.g.
row1=green, row2=blue, row3=green, row4=blue, ...) for a for-each loop. Is
there an easy way to achieve this?
I've tried to get the element position so I can check if it is even or not.
But it looks like I can't get the absolute position of an element in a list
with 'position()' inside a 'for-each' loop.
Any ideas??
Thanks,
-michael
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








