This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

alternating bg colour in nested data


Hi all,

Im trying to get alternating table row background colours from nested xml.

The xml is essentially nested groups.  1 contains 2,3 and 4. 2 contains 3
and 4 and so on.

(This indicates that a group belongs to its parent and will be rendered
expandable-collapsable-windows-explorer stylee)

For example:

<group1>
  <data1/>
  <data2/>
  <group2>
    <data1/>
    <data2/>
  </group2>
  <group2>
    <data1/>
    <data2/>
    <group3>
      <data1/>
      <data2/>
    </group3>
    <group3>
      <data1/>
      <data2/>
      <group4>
        <data1/>
        <data2/>
      </group4>
    </group3>
  </group2>
</group1>


I currently get alternating row colours using this kind of template for each
group:

<xsl:template match="group1">
<xsl:variable name="position" select="position()" />
<xsl:choose>
  <xsl:when test="$position mod 2 = 1">
    <xsl:call-template name="row_even"/>
  </xsl:when>
  <xsl:otherwise>
    <xsl:call-template name="row_odd"/>
  </xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="group2"/>
</xsl:template>

Each template is virtually identical apart from the 'groupX' number. Also,
occasionally two adjacent rows share the same colour (where group changes
and last elem pos was even)

Is there any way I can reduce the duplication in each template, and sort out
the ocassional lapse in alternating  colours?

cheers

andrew

===




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]