[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] RE: Problem With Different Colors for Alternate Rows


Subject: Re: [xsl] RE: Problem With Different Colors for Alternate Rows
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 05 Nov 2002 09:10:38 -0500

At 2002-11-05 08:46 -0500, Schwartz, Rechell R, ALCAS wrote:
I was wondering if I can output the HTML as an XML file,

Use <xsl:output method="xml"/> to ensure the processor doesn't engage the default method of HTML when it sees the document element of the result.


and then apply a second XSLT stylesheet on the HTML file that would loop through each row of the table and make alternativing rows different colors. Any ideas on how each of the two stylesheets should look like would be appreciated.

Use an identity transform and then special case the rows you need to be handled differently ... an example is below, though I am unsure if you are or are not already using the style attribute for other purposes.


I hope this helps.

............. Ken

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:template match="node()|@*"> <!--identity transform-->
  <xsl:copy>
    <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="tr[ position() mod 2 = 0 ]">
  <xsl:copy>
    <xsl:attribute name="style">background:silver</xsl:attribute>
    <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="tr[ position() mod 2 = 1 ]">
  <xsl:copy>
    <xsl:attribute name="style">background:white</xsl:attribute>
    <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>


-- Upcoming hands-on in-depth XSLT/XPath and/or XSL-FO: - North America: Feb 3 - Feb 7,2003

G. Ken Holman               mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.        http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0  +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                     Definitive XSLT and XPath
ISBN 0-13-140374-5                             Definitive XSL-FO
ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
ISBN 1-894049-10-1             Practical Formatting Using XSL-FO
Next conference training:                    2002-12-08,03-03,06


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list




Current Thread
Keywords