RE: [xsl] Different Colors for Alternating Rows

Subject: RE: [xsl] Different Colors for Alternating Rows
From: "Schwartz, Rechell R, ALABS" <rrschwartz@xxxxxxx>
Date: Wed, 25 Jun 2003 22:05:15 -0500
Jarno,

Since I had over 6000 rows, I needed to add a fix to my VM to increase
stack capacity. I still have blown my stack, and got the following
error. Switching to saxon is not an option at this point (can't change
the architecture). Also, I tried it on a smaller file and it almost
worked --
The rows, however were concatenated and printed together as a single
line.

Rechell

Any clue would be appreciated.

####<Jun 25, 2003 10:55:01 PM EDT> <Error> <HTTP> <maeder> <FM>
<ExecuteThread: '7' for queue: 'default'> <> <> <101020> <[WebAppSer
vletContext(7821805,DefaultWebApp_FM,/DefaultWebApp_FM)] Servlet failed
with Exception>
java.lang.StackOverflowError
        at
weblogic.apache.xpath.VariableStack.getVariable(VariableStack.java:432)
        at
weblogic.apache.xpath.XPathContext.getVariable(XPathContext.java:256)
        at
weblogic.apache.xpath.operations.Variable.execute(Variable.java:110)
        at weblogic.apache.xpath.XPath.execute(XPath.java:269)
        at
weblogic.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:143)
        at
weblogic.apache.xalan.transformer.TransformerImpl.executeChildTemplates(
TransformerImpl.java:2208)
        at
weblogic.apache.xalan.transformer.TransformerImpl.transformToRTF(Transfo
rmerImpl.java:1828)
        at
weblogic.apache.xalan.templates.ElemVariable.getValue(ElemVariable.java:
293)
        at
weblogic.apache.xalan.templates.ElemVariable.execute(ElemVariable.java:2
55)

Thanks,
Rechell Schwartz

-----Original Message-----
From: Jarno.Elovirta@xxxxxxxxx [mailto:Jarno.Elovirta@xxxxxxxxx] 
Sent: Tuesday, June 24, 2003 9:33 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
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


Current Thread