[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|