Re: [xsl] declarative language, need for loops etc.

Subject: Re: [xsl] declarative language, need for loops etc.
From: Mike Brown <mike@xxxxxxxx>
Date: Wed, 16 Oct 2002 10:37:24 -0600 (MDT)
thomas wrote:
> In my experience as an beginner in xslt I understand slowly whats 
> "behind" xslt as a declarative language. What I dont understand is, that 
> there is still some "need" for iterative solutions wich is not part in 
> the xslt.
> And I have to do something like this:
> Wich basic concepts is missing? What do I not understand?

Accumulators (variables that change, for computing totals/subtotals) can be
simulated with recursive function calls, thus eliminating the need for each
iteration to preserve its state or to modify the state of something on the
side ("having side effects"); or they can be circumvented entirely by
redefining how totals are calculated. Very often, the info one needs to 
compute the subtotal is available to other functions like sum(), with a 
creative XPath expression to select the right input nodes.

Iterating a fixed number of times is often a solution to generating
paginated/grouped output (n iterations per page, for example), and this is
easily solved by defining output in terms of a page for every (n)th item,
where a page contains that item and the next (n-1) items. For more complex
grouping problems, there are less natural but very effective ways of solving
them, as explained at, in Michael Kay's XSLT Reference
book (among others), and in the FAQ at

Of course, there are still times when you might really need a fixed number of
iterations where the number has nothing to do with the input XML, in which
case there is the recursive template solution, also in the FAQ.

If you have reviewed those resources and still have a specific problem where
you think you need a procedural solution, post it here (reducing it to a
simple test case if possible), with your input XML and desired output. One of
the many helpful people on the list will almost certainly tell you what the
declarative, functional way of doing it is.

   - Mike
  mike j. brown                   |  xml/xslt:
  denver/boulder, colorado, usa   |  resume:

 XSL-List info and archive:

Current Thread