Alternating table row colors WITHOUT using position()

R

Ralph Snart

Is there a way to alternate table row colors without using the
position() mod 2 trick? I'm in a series of nested xsl:for-each
elements, about 3 deep, and I want to alternate the table row
color all the way through. position() resets to 1 whenever
the inner for-each loops around, of course.

Example code:

<xsl:for-each select="/games/game[count(. | key('platforms', platform)[1]) = 1]">
<xsl:sort select="platform"/>
<xsl:variable name="platform" select="platform"/>
<xsl:for-each select="/games/game[date = $date][region = $region][platform = $platform]">
<xsl:sort select="title"/>
<tr class="???????" bgcolor="???????">
<td>
<xsl:choose>
<xsl:when test="position() = 1"><xsl:value-of select="platform"/></xsl:when>
<xsl:eek:therwise>&nbsp;</xsl:eek:therwise>
</xsl:choose>
</td>
<td><a href="{path}/data/{id}.html"><xsl:value-of select="title"/></a></td>
<td><xsl:value-of select="genre"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>

-rs-
 
D

Dimitre Novatchev

This can be done in two steps:

Step1:

<xsl:variable name="vrtfMyRows">
<xsl:for-each select="/games/game[count(. | key('platforms', platform)[1]) = 1]">
<xsl:sort select="platform"/>
<xsl:variable name="platform" select="platform"/>
<xsl:for-each select="/games/game[date = $date][region =
$region][platform = $platform]">
<xsl:sort select="title"/>
</xsl:for-each>
</xsl:for-each>

</xsl:variable>

Step2:

<xsl:for-each select="ext:node-set($vrtfMyRows)/*">
<!-- Produce the table with alternating rows using position() mod 2 -->
</xsl:for-each>



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL





Ralph Snart said:
Is there a way to alternate table row colors without using the
position() mod 2 trick? I'm in a series of nested xsl:for-each
elements, about 3 deep, and I want to alternate the table row
color all the way through. position() resets to 1 whenever
the inner for-each loops around, of course.

Example code:

<xsl:for-each select="/games/game[count(. | key('platforms', platform)[1]) = 1]">
<xsl:sort select="platform"/>
<xsl:variable name="platform" select="platform"/>
<xsl:for-each select="/games/game[date = $date][region =
$region][platform = $platform]">
<xsl:sort select="title"/>
<tr class="???????" bgcolor="???????">
<td>
<xsl:choose>
<xsl:when test="position() = 1"><xsl:value-of
 
R

Ralph Snart

<xsl:for-each select="ext:node-set($vrtfMyRows)/*">

is it possible to do this without ext:node-set? i use sablotron which doesn't
support that extension.

-rs-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top