[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

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.