xsl-list
[Top] [All Lists]

Re: [xsl] XSLT repetition constructs

2019-03-05 14:02:03
 I don’t 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 
threshold.

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
Saxonica
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>