[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Different Colors for Alternating Rows

Subject: RE: Different Colors for Alternating Rows
From: Jarno.Elovirta@xxxxxxxxx
Date: Tue, 24 Jun 2003 16:33:08 +0300
td background image
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.