Subject: RE: [xsl] Different Colors for Alternating Rows From: Jarno.Elovirta@xxxxxxxxx Date: Tue, 24 Jun 2003 16:33:08 +0300 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Different Colors for Alternat, Schwartz, Rechell R, | Thread | RE: [xsl] Different Colors for Alte, Schwartz, Rechell R, |
Re: [xsl] Optimizing Trax, Mark R. Diggory | Date | RE: [xsl] Looping in XSLT(old quest, Jeff Beadle |
Month |