Jarno,
Thank you. The second approach did not work. It seemd to create an endless
loop. Here is the error that I got, which repeated endlessly:
at weblogic.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:152)
at
weblogic.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.java:498)
at
weblogic.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:193)
at
weblogic.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2208)
Rechell Schwartz
-----Original Message-----
From: Jarno(_dot_)Elovirta(_at_)nokia(_dot_)com
[mailto:Jarno(_dot_)Elovirta(_at_)nokia(_dot_)com]
Sent: Tuesday, June 24, 2003 9:33 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Different Colors for Alternating Rows
Hi,
...
<xsl:template match="table/tr[td[not(a) and not(@class)]]">
...
For one, you can simplify your stylesheet by rewriting this to
<xsl:template match="tr[td[not(a or @class)]]">
<xsl:copy>
<xsl:variable name="x">
<xsl:choose>
<xsl:when test="count(preceding-sibling::tr[td[not(a or @class)]])
mod 2 = 1">evenMedium</xsl:when>
<xsl:otherwise>oddMedium</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:for-each select="td[1]">
<td class="{$x}" width="35%">
<xsl:apply-templates select="node()|@*"/>
</td>
</xsl:for-each>
<xsl:for-each select="td[2]">
<td class="{$x}" width="65%">
<xsl:apply-templates select="node()|@*"/>
</td>
</xsl:for-each>
</xsl:copy>
</xsl:template>
But a recursive solution could be something like
<xsl:template match="node()|@*" name="copy">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="table">
<xsl:copy>
<xsl:apply-templates select="@*|tr[1]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="tr">
<xsl:param name="odd" select="true()"/>
<xsl:choose>
<xsl:when test="td[not(a or @class)]">
<xsl:variable name="x">
<xsl:choose>
<xsl:when test="$odd">odd</xsl:when>
<xsl:otherwise>even</xsl:otherwise>
</xsl:choose>
<xsl:text>Medium</xsl:text>
</xsl:variable>
<xsl:for-each select="td[1]">
<td class="{$x}" width="35%">
<xsl:apply-templates select="node()|@*"/>
</td>
</xsl:for-each>
<xsl:for-each select="td[2]">
<td class="{$x}" width="65%">
<xsl:apply-templates select="node()|@*"/>
</td>
</xsl:for-each>
<xsl:apply-templates select="following-sibling::tr[1]">
<xsl:with-param name="odd" select="not($odd)"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="copy"/>
<xsl:apply-templates select="following-sibling::tr[1]">
<xsl:with-param name="odd" select="$odd"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Cheers,
Jarno - Mark Kavanagh: One Hour DJ Mix
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list