Re: [xsl] XSLT repetition constructs

Subject: Re: [xsl] XSLT repetition constructs
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 5 Mar 2019 20:01:59 -0000
>  I donbt have enough experience
> with using xs:iterate in larger stylesheets

xsl:iterate has two main applications

(a) when you want to stop processing input elements when some condition
becomes true (e.g. when you hit the first <pageBreak> element)

(b) when you want the result of processing one input element to depend on the
results of processing previous elements; for example, if you want to insert a
page break when the sum of the sizes of previous elements exceeds some

We reported at XML Prague on the XSLT compiler we are writing in XSLT, and
that uses xsl:iterate very extensively. For example, when you're processing
the instructions in a sequence constructor, you want to keep track of which
local variables are in scope, so you want to process instructions sequentially
keeping the set of local variables as current state.

You can always achieve the same effect using recursion. But after years of
practice, I still find recursive templates are a pig to debug.

The reason for introducing xsl:iterate was because (compared with recursive
templates) it makes the streamability analysis feasible. But it ends up being
a very convenient construct quite independent of streaming. In fact, it's easy
to slip into using it all the time, in place of xsl:for-each. If there's no
xsl:break, xsl:param, xsl:next-iteration, xsl:on-completion, or xsl:sort, then
the two constructs are 100% equivalent.

Michael Kay

Current Thread