Altova Mailing List Archives

Re: [xsl] Problem With Different Colors for Alternate Rows

From: Joerg Heinicke <joerg.heinicke@------>
Date: 11/4/2002 8:07:00 PM
Hello Rechell,

there is also a simple XSL way:

<xsl:template match="/Food_List">


    <xsl:apply-templates select="Main_Food_List | Side_Dish | Desert" 



<xsl:template match="*" mode="row">
  <TR class="evenRowStyle">
    <xsl:if test="position() mod 2 = 1">
      <xsl:attribute name="class">oddRowStyle</xsl:attribute>
    <xsl:apply-templates select="."/>

<xsl:template match="Main_Food_List">
  <TD>Main Course:</TD>
  <TD><xsl:value-of select="Main_Course"/></TD>

<xsl:template match="Side_Dish">
  <TD>Side Dish:</TD>
  <TD><xsl:value-of select="."/></TD>

<xsl:template match="Desert">
  <TD><xsl:value-of select="Fancy_Desert"/></TD>



Schwartz, Rechell R, ALCAS wrote:

I am having difficulty programming a stylesheet that is supposed to return the result set as a list of HTML rows in alternating colors.All of the examples that I have seen address how to do this if every data row is is derived from the same type of XML tag. But in my example, each row may come from a completely different section of the XML. Following is a sample XML similar to the one that I am using. Also, another constraint is if any row is missing, it is inhibited, and the alternating color rule must still be preserved. I have tried numerous ways of passing parameters, but have been unable to modify the the row count after a match was found ofr each item. Any help would be GREATLY appreciated.

Sample XML:

Chocolate Truffles

Sample XSLT Stylesheet:
<?xml version="1.0" ?>
<xsl:stylesheet version='1.0' xmlns:xsl='' >
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="Food_List/Main_Food_List/Main_Course"/>
<xsl:apply-templates select="Food_List/Side_Dish"/>
<xsl:apply-templates select="Food_List/Desert/Fancy_Desert"/>

<xsl:template match="Main_Course">
<TR><TD>Main Course:</TD><TD xsl:value-of select="."/></TD></TR>

<xsl:template match="Side_Dish">
<TR><TD>Side Dish:</TD><TD xsl:value-of select="."/></TD></TR>

<xsl:template match="Fancy_Desert">
<TR><TD>Desert:</TD><TD xsl:value-of select="."/></TD></TR>


Required HTML Output
<TR><TD colspan="2">MENU</TD></TR>
<TR><TD class="oddRowStyle">Main Dish:</TD><TD class="oddRowStyle">Chicken</TD></TR>
<TR><TD class="evenRowStyle">Side Dish:</TD><TD class="oddRowStyle">Potatoes</TD></TR>
<TR><TD class="oddRowStyle">Desert:</TD><TD class="oddRowStyle">Chocolate Truffles</TR>

XSL-List info and archive:


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.