You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Gunter D'Hondt <gu...@sofico.be> on 2005/10/13 11:23:37 UTC

[Solved] Re: repeaters & alternate row colours

Yep, thanks for the xslt code snippet!
Only a few adjustments so that the tbody is not necessary and the rest of 
the html is copied again:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:template match="table/@alternate" />

 <xsl:template match="table[@alternate ='true']">
        <table>
                <xsl:copy-of select="@*"/>
                <xsl:apply-templates select="tr" mode="alternate"/>
        </table>
 </xsl:template>

 <xsl:template match="tr" mode="alternate">
                 <xsl:copy>
                                 <xsl:apply-templates select="@*" />
                                 <xsl:attribute name="class">
                                                 <xsl:choose>
                                                                 <xsl:when 
test="position() mod 2 = 1">
  <xsl:text>GridRowOdd</xsl:text>
 </xsl:when>
 <xsl:otherwise>
  <xsl:text>GridRowEven</xsl:text>
 </xsl:otherwise>
                                                 </xsl:choose>
                                 </xsl:attribute>
                                 <xsl:apply-templates select="node() | @*" 
/>
                 </xsl:copy>
 </xsl:template>

  <xsl:template match="@*|node()" priority="-1">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Regards,
Gunter







Mark Lundquist <ml...@wrinkledog.com> 
13/10/2005 10:07
Please respond to
users@cocoon.apache.org


To
users@cocoon.apache.org
cc

Subject
FW_SPAM: Re: repeaters & alternate row colours







On Oct 13, 2005, at 1:02 AM, Gunter D'Hondt wrote:

> as Jorg also mentoined; I'm still using 2.1.4 (and cannot upgrade that
> quickly) so as far as I know I can't use the jx macros in that version
> any other possibilities?

Sure.  I use XSLT for this, that way I can get this effect for any 
table I want, not just repeaters.

E.g.,

<xsl:stylesheet version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

         <xsl:template match="table/@alternate" />

         <xsl:template match="table[@alternate ='true']/tbody">
                 <tbody>
                         <xsl:apply-templates select="tr" 
mode="alternate"/>
                 </tbody>
         </xsl:template>

         <xsl:template match="tr" mode="alternate">
                 <xsl:copy>
                         <xsl:apply-templates select="@*" />
                         <xsl:attribute name="class">
                                 <xsl:choose>
                                         <xsl:when test="position() mod 
2 = 1">
                                                 <xsl:text>odd</xsl:text>
                                         </xsl:when>
                                         <xsl:otherwise>
 
<xsl:text>even</xsl:text>
                                         </xsl:otherwise>
                                 </xsl:choose>
                         </xsl:attribute>
                         <xsl:apply-templates select="node() | @*" />
                 </xsl:copy>
         </xsl:template>

</xsl:stylesheet>

HTH,
—ml—


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org