-----Original Message-----
From: Frankie Roberto <public(_at_)frankieroberto(_dot_)com>
Subject: [xsl] for-loop in xslt problem
To explain, my XML looks something like:
<total>45</total>
<skip>20</skip>
The PHP script I am converting would do something like this:
for ($count = 0; $count<=$total; ($count = $count + $skip)) {
echo("Print this");
}
This is one of those oft-answered questions which is rooted in the difference
in world-view between functional and procedural programming, with XSLT being
the former camp and PHP being an instance of the latter.
You need to approach this as a problem in recursive template calling. You
didn't provide enough XML for me to test this, so I may have something wrong,
but try this for a first cut at the problem:
<xsl:template match="total" name="something">
<xsl:param name="count" select="0" />
<xsl:variable name="local-count"><xsl:value-of
select="following-sibling::node()[name()='skip']" /></xsl:variable>
<xsl:variable name="local-total"><xsl:value-of select="." /></xsl:variable>
<xsl:if test="($count + $local-count) < $local-total">
<!-- whatever passes for 'echo("Print this");' goes here -->
<xsl:call-template name="something">
<xsl:with-param name="count"><xsl:value-of select="$count + $local-count"
/></xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
--
Charles Knell
cknell(_at_)onebox(_dot_)com - email
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list