Subject: RE: [xsl] for-loop in xslt problem From: cknell@xxxxxxxxxx Date: Sat, 05 Apr 2003 10:45:57 -0500 |
> -----Original Message----- > From: Frankie Roberto <public@xxxxxxxxxxxxxxxxxx> > 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@xxxxxxxxxx - email XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] for-loop in xslt problem, Ryan Gallagher | Thread | [xsl] Attribute Value Template, David B. Bitton |
[xsl] Re: for-loop in xslt problem, Dimitre Novatchev | Date | Re: [xsl] reference external javasc, bix_xslt |
Month |