[xsl] How to increase the counter programmatically

Subject: [xsl] How to increase the counter programmatically
From: "Thang X. Le" <tle@xxxxxxxxxxx>
Date: Thu, 01 Sep 2005 10:22:18 -0700
In a <xsl:for-each> loop, I know how to find the 
processing order (counter) by calling position(). But how can
I find the counter when it's supposed to increase only in
specific conditions? For example:

<xsl:for-each select="//products/product">
<!-- Do some processing here -->
<xsl:if test="condition">
    <!-- What is the counter here? -->

Now, I know that if the "condition" is simple and straightforward,
I can just do this and use position() as counter:

<xsl:for-each select="//products/product[condition]">
<!-- Do some processing here -->
<!-- Now position() will be the ordinal counter -->

But what if the condition is more complex and require extra steps?
For example, I may want to store a few nodesets in variables, and
use these variables in the 'test' clause and body of <xsl:if>.

I've tried twisting it to use <xsl:template> but it seems the basic
problem is still there. Basically this can be solved easily if I can
do something like $counter = $counter + 1. I know this is not on
with XSLT, so what are my alternatives?


Thang Le

Current Thread