Off Topic - XSL Formatting Row Colours

Hi Chris,

> I have this XSL code, but I am trying to get it so every other row colour is
> light grey and the ones in between are white ...
>
> <?xml version='1.0'?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
> <xsl:template match="/">
> Â <html>
> Â <body>
> Â Â Â <table border="2" bgcolor="yellow">
> Â Â Â Â Â <tr>
> Â Â Â Â Â Â Â <th>OrderNum</th>
> Â Â Â Â Â Â Â <th>Date</th>
> Â Â Â Â Â </tr>
> Â Â Â Â Â <xsl:for-each
> select="ExportQuery/ELEC01_SalesOrdersWaitingParts[Customer_CustID='M035']">
> Â Â Â Â Â Â <tr>
> Â Â Â Â Â Â Â <td><xsl:value-of select="OrderHed_OrderNum"/></td>
> Â Â Â Â Â Â <xsl:choose>
> Â Â Â Â Â Â Â Â Â <xsl:when match=".[OrderHed_OrderDate='31/01/11']">
> Â Â Â Â Â Â Â Â Â Â Â <td bgcolor="#ff0000"><xsl:value-of
> select="OrderHed_OrderDate"/></td>
> Â Â Â Â Â Â Â Â Â </xsl:when>
> Â Â Â Â Â Â Â Â Â <xsl:otherwise>
> Â Â Â Â Â Â Â Â Â Â Â <td><xsl:value-of select="OrderHed_OrderDate"/></td>
> Â Â Â Â Â Â Â Â Â </xsl:otherwise>
> Â Â Â Â Â Â Â </xsl:choose>
> Â </tr>
> Â Â Â Â Â </xsl:for-each>
> Â Â Â </table>
> Â </body>
> Â </html>
> </xsl:template>
> </xsl:stylesheet>
>
> As it stands, it is highlighting rows in red which contain 31/01/11.
>
> Any help would be appreciated so I can get it to colour each alternate row.

First of all, don't use bgcolor directly. Use class attributes and set
the color through a spreadsheet. It doesn't change your problem but it
makes coloring much easier to change later. So what you want to do is
to place a different class attribute on every other row. Here's one
idea:

<tr>
<xsl:if test="position() mod 2 = 1">
<xsl:attribute name="class">odd</xsl:attribute>
</xsl:templates>
<!-- something --->
</tr>

This would add a class="odd" to every other row. You can then set the
bgcolor in a stylesheet.

I didn't test it but you can play with it.

Cheers,

Mark W.
Hi All

I have this XSL code, but I am trying to get it so every other row colour is
light grey and the ones in between are white ...

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
 <html>
 <body>
   <table border="2" bgcolor="yellow">
     <tr>
       <th>OrderNum</th>
       <th>Date</th>
     </tr>
     <xsl:for-each
select="ExportQuery/ELEC01_SalesOrdersWaitingParts[Customer_CustID='M035']">
      <tr>
       <td><xsl:value-of select="OrderHed_OrderNum"/></td>
      <xsl:choose>
         <xsl:when match=".[OrderHed_OrderDate='31/01/11']">
           <td bgcolor="#ff0000"><xsl:value-of
select="OrderHed_OrderDate"/></td>
         </xsl:when>
         <xsl:otherwise>
           <td><xsl:value-of select="OrderHed_OrderDate"/></td>
         </xsl:otherwise>
       </xsl:choose>
 </tr>
     </xsl:for-each>
   </table>
 </body>
 </html>
</xsl:template>
</xsl:stylesheet>


As it stands, it is highlighting rows in red which contain 31/01/11.

Any help would be appreciated so I can get it to colour each alternate row.

Thanks.




[Non-text portions of this message have been removed]