RE: Different Colors for Alternating Rows
2003-06-24 07:01:03
Hello Rechell,
I'm curious, why are you implementing the alternating color style within the
td's and not the tr's.
-Jeff
-----Original Message-----
From: Schwartz, Rechell R, ALABS [mailto:rrschwartz(_at_)att(_dot_)com]
Sent: Tuesday, June 24, 2003 8:46 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Different Colors for Alternating Rows
All,
I have bee using the following stylesheet to produce different colors for
alternating rows whenever a row that has <td> tags without attributes or
hyperlinks are encountered. The problem is for large documents the
performance degrades significantly. This seems to be because in the
algorithm used to calculate which color to use, a check is made to determine
how many previous siblings have already been processed, so the number of
checks grows exponentially as the number of rows grows.
It seems that that the same effect should be possible with greatly improved
performance by recursively incrementing a variable whenever a row that is a
candidate for a color change has been processed. I was unsure of how to go
about doing this. Any code snippets would be greatly appreciated. Following
is my stylesheets, sample HTML, and desire output:
Thanks,
Rechell Schwartz
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" indent="yes"/>
<xsl:template match="node()|@*"> <!--identity transform-->
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="table/tr[td[not(a) and not(@class)]]">
<xsl:copy>
<xsl:choose>
<xsl:when test="count( preceding-sibling::tr[td[not(a) and
not(@class)]] ) mod 2 = 1">
<xsl:for-each select="td[1]">
<td class="evenMedium" width="35%">
<xsl:apply-templates select="node()|@*"/>
</td>
</xsl:for-each>
<xsl:for-each select="td[2]">
<td class="evenMedium" width="65%">
<xsl:apply-templates select="node()|@*"/>
</td>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="td[1]">
<td class="oddMedium" width="35%">
<xsl:apply-templates select="node()|@*"/>
</td>
</xsl:for-each>
<xsl:for-each select="td[2]">
<td class="oddMedium" width="65%">
<xsl:apply-templates select="node()|@*"/>
</td>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The input file is:
<table>
<tr>
<td class="headerStyle" colspan="2">
Title
</td>
</tr>
<tr>
<td>Label1</td>
<td>Value1</td>
</tr>
<tr>
<td class="separatorStyle colspan="2">
---------------
</td>
</tr>
<tr>
<td>Label2</td>
<td>Value2</td>
</tr>
</table>
The desired output:
<table>
<tr>
<td class="headerStyle" colspan="2">
Title
</td>
</tr>
<tr>
<td class="oddRowStyle" width="35%">Label1</td>
<td class="oddRowStyle" width="65%">Value1</td>
</tr>
<tr>
<td class="separatorStyle colspan="2">
---------------
</td>
</tr>
<tr>
<td class="evenRowStyle" width="35%">Label2</td>
<td class="evenRowStyle" width="65%">Value2</td>
</tr>
</table>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
<Prev in Thread] |
Current Thread |
[Next in Thread>
|
- Different Colors for Alternating Rows, Schwartz, Rechell R, ALABS
- RE: Different Colors for Alternating Rows, Jarno . Elovirta
- RE: Different Colors for Alternating Rows, Schwartz, Rechell R, ALABS
- RE: Different Colors for Alternating Rows,
Jeff Beadle <=
- RE: Different Colors for Alternating Rows, Schwartz, Rechell R, ALABS
- RE: Different Colors for Alternating Rows, Kienle, Steven C [IT/0200]
- RE: Different Colors for Alternating Rows, Schwartz, Rechell R, ALABS
- RE: Different Colors for Alternating Rows, Jarno . Elovirta
- RE: Different Colors for Alternating Rows, Zink, Juergen
- RE: Different Colors for Alternating Rows, Joseph Kesselman
- RE: Different Colors for Alternating Rows, Schwartz, Rechell R, ALABS
- RE: Different Colors for Alternating Rows, Schwartz, Rechell R, ALABS
- RE: Different Colors for Alternating Rows, Schwartz, Rechell R, ALABS
- RE: Different Colors for Alternating Rows, Zink, Juergen
|
Previous by Date: |
RE: Different Colors for Alternating Rows, Schwartz, Rechell R, ALABS |
Next by Date: |
RE: Different Colors for Alternating Rows, Schwartz, Rechell R, ALABS |
Previous by Thread: |
RE: Different Colors for Alternating Rows, Michael Kay |
Next by Thread: |
RE: Different Colors for Alternating Rows, Schwartz, Rechell R, ALABS |
Indexes: |
[Date]
[Thread]
[Top]
[All Lists] |
|
|