This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: how to increment a variable in a for-each loop
- From: Matthew Jaquish <mjaquish at cisco dot com>
- To: bytj at yahoo dot com
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 23 Jan 2002 15:53:28 -0800
- Subject: Re: [xsl] how to increment a variable in a for-each loop
- References: <200201232230.WAA24767@penguin.nag.co.uk>
- Reply-to: xsl-list at lists dot mulberrytech dot com
You are getting all red cells because in your XSL for-each statement, you are only selecting the current node. So there is only 1 element in your for-each set. Instead of selecting itself (.), you need to select the element name that so that all of those elements are in the set that you want to test with the mod checks.
Instead of:
<xsl:for-each select=".">
You want:
<xsl:for-each select="yourElementName">
Hope that helps,
...Matt
At 03:14 PM 1/23/2002 -0800, yan bai wrote:
>I have a code snippet as below:
><xsl:template match="*" mode="diff_cols">
><xsl:for-each select=".">
> <xsl:if test="position() mod 2 = 1">
> <fo:table-cell background-color="red">
><fo:block><xsl:value-of select="."/></fo:block>
> </fo:table-cell>
> </xsl:if>
> <xsl:if test="position() mod 2 = 0">
> <fo:table-cell background-color="blue">
> <fo:block><xsl:value-of
>select="."/></fo:block>
> </fo:table-cell>
> </xsl:if>
> </xsl:for-each>
></xsl:template>
>
>Unfortunately, it did not work. The background color
>in all columns is red.
>
>Can you help to debug?
>
>
>Yan
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list