Posted on 2006-06-15
I'm new to XSLT, just using it to transform some simple stuff in Java.
I'm making a table, and I want every other entry to have a colored background. However, every other entry doesn't mean every other row. There are nested for-each statements to select data. A small example might help:
<!-- stuff to populate the row -->
<!-- more stuff -->
So, I want every other entry to be colored - that is every other loop through the outer "for-each" to be colored (and all the loops through the inner for-each to have the same color as the outer).
This is what I've tried
<xsl:variable name="posn" select="(position() mod 2)" />
<xsl:if test="$posn = 1">
<xsl:attribute name="style">background: #ffffff</xsl:attribute>
<xsl:if test="$posn = 0">
<xsl:attribute name="style">background: #e4eef7</xsl:attribute>
This works for the outer loop, but when I add the if's to the inner loop, it says it can't resolve $posn. I guess I don't understand XSLTs scoping rules.
I tried other ways (i.e. just testing the position and making the value of the background a variable), but it's the same variable problem.