Re: [xsl] How is fold-left useful to XSLT streaming?

Subject: Re: [xsl] How is fold-left useful to XSLT streaming?
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Tue, 10 Dec 2013 10:51:34 +0000
Suppose you have data which gives the increase in prices in any given year

<year n="1692" inflation="1.02"/>
<year n="1693" inflation="1.03"/>

and you want to calculate the increase over the entire period, by multiplying
the values of all the @inflation values in the sequence.

fold-left(year[@n ge 1692 and @n le 2013]/@inflation, 1, function($z as
xs:double, $this as xs:double) {$z * $this})

This will be streamable in the next XSLT 3.0 draft. Note that it depends on
the function being defined to operate on atomic values, to make sure that it
doesn't navigate away from the attribute node to other places in the streamed

The same calculation can also be achieved using xsl:iterate.

Michael Kay

On 10 Dec 2013, at 10:29, Costello, Roger L. <costello@xxxxxxxxx> wrote:

> On Friday, November 22, 2013 Michael Kay wrote:
>> There are plenty of techniques still available for
>> streamed processing: accumulators, xsl:iterator,
>> fold-left, xsl:fork.
> I understand the usefulness of accumulators, xsl:iterator, and xsl:fork to
> I am unclear on the usefulness of fold-left to streaming.
> Would you (Michael or anyone) provide an example to illustrate the
usefulness of fold-left to streaming please?
> /Roger

Current Thread