xsl-list
[Top] [All Lists]

Table alternate rows colors within xsl:sort

2003-11-20 01:39:59
I would want to display a datagrid which lines colors
varies regarding the position (one line white, one
line gray, one line white, ...) AFTER an xsl:sort.

The problem is that the "<xsl:if test="position() mod
2 = 0"> won't work after a <xsl:sort> because the
position() function returns the position in the
original xml, not the in sorted nodes.

I can't use a variable because xslt do not allow to
increment it within my xsl:for-each

Do someone know a solution to this ?

<xsl:template name="list">
<xsl:param name="type"/>
<table class="table" cellpadding="2" cellspacing="1" width="100%">
        <xsl:for-each select="links/link">
                <xsl:sort order="ascending" select="name"/>

                <!--This won't work-->
                <xsl:variable name="i" select="$i + 1"></xsl:variable>

                <xsl:if test="@type = $type">
                        <xsl:choose>
                                <xsl:when test="$i mod 2 = 0">
                                        <tr>
                                                <td 
class="tablerow1"><xsl:value-of select="$i"/><a href="{url}"><xsl:value-of
select="name"/></a></td>
                                                <td 
class="tablerow1"><xsl:value-of select="url"/></td>
                                        </tr>
                                </xsl:when>
                                <xsl:otherwise>
                                        <tr>
                                                <td class="tablerow2"><a 
href="{url}"><xsl:value-of select="$i"/><xsl:value-of
select="name"/></a></td>
                                                <td 
class="tablerow2"><xsl:value-of select="url"/></td>
                                        </tr>
                                </xsl:otherwise>
                        </xsl:choose>
                </xsl:if>
        </xsl:for-each>
</table>
</xsl:template>

Regards,
Mike.

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

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



<Prev in Thread] Current Thread [Next in Thread>