Re: [xsl] for-loop in xslt problem

Subject: Re: [xsl] for-loop in xslt problem
From: bix_xslt@xxxxxxxxxxx
Date: Fri, 4 Apr 2003 20:53:40 -0600
Frankie,

This is a common problem for those of us who have just picked up XML and
learned that writing XML is quite different than most other common
languages.  To tackle this problem, you need to look at the for loop in a
slightly different manner.  XML does not have a mechanism for updating
"variables" without using recursion.  So, if I take a little liberty and
modify your for loop, you might see some psuedo-code like this:

variable  max = value-of total;
variable  skip = value-of skip;
call forLoop                            //  this starts the recursion
    with param total = max;
    with param skip = skip;


function forLoop (count, total, skip) {
     param name count = 0;
     param name total = $max;
     param name skip = $skip;

         //  if we haven't made it to the total yet, then repeat the call
         if  test = $count lessThan total {
                print "Print This!";
                call forLoop
                    with param count = count + skip;
                    with param total = total;
                    with param skip = skip;
         }
}

Hope that makes sense!
bix


----- Original Message -----
From: "Frankie Roberto" <public@xxxxxxxxxxxxxxxxxx>
To: "Xsl-List@Lists. Mulberrytech. Com" <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, April 04, 2003 7:55 PM
Subject: [xsl] for-loop in xslt problem


>
> Hi,
>
> I'm having problems trying to implement a 'for' loop in xslt - I haven't
> seen any syntax so far that can cope with this (and my book doesn't go
into
> it).
>
> 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");
>
> }
>
> ..looping $total/$skip times plus once for the remainder.
>
> But I can't see any way of doing this in xslt so far...
>
> Ta.
>
> Frankie
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread