RE: [xsl] alternating table background colour in an for-each 'loop'

Subject: RE: [xsl] alternating table background colour in an for-each 'loop'
From: "Tim Watts" <timw@xxxxxxx>
Date: Thu, 19 Jul 2001 16:23:42 +1000

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

An example is shown below, using a CSS.

<xsl:template match="products">
    <xsl:when test="position() mod 4 = 0">
      <tr class="red">
        <xsl:call-template name="showproducts" />
    <xsl:when test="position() mod 4 = 1">
      <tr class="green">
        <xsl:call-template name="showproducts" />
    <xsl:when test="position() mod 4 = 2">
      <tr class="blue">
        <xsl:call-template name="showproducts" />
    <xsl:when test="position() mod 4 = 3">
      <tr class="pink">
        <xsl:call-template name="showproducts" />

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
Sent: Thursday, 19 July 2001 11:31 AM
To: xsl list
Subject: [xsl] 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??


 XSL-List info and archive:

 XSL-List info and archive:

Current Thread