[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: for-loop in xslt problem

Subject: RE: for-loop in xslt problem
From: cknell@xxxxxxxxxx
Date: Sat, 05 Apr 2003 10:45:57 -0500
xslt loop count
> -----Original Message-----
> From:     Frankie Roberto <public@xxxxxxxxxxxxxxxxxx>
> Subject:   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) &lt; $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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.