[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] The output of evaluating an XSLT transform is the same regardless of the order in which output elements are evaluated. Right?


Subject: RE: [xsl] The output of evaluating an XSLT transform is the same regardless of the order in which output elements are evaluated. Right?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 13 Apr 2010 13:47:13 +0100

> QUESTION #1
> 
> Why do you now say "XSLT instructions"?

Because that's what the XSLT specification calls them. But semantically,
they are expressions. In fact, XSLT 1.0 did use the kind of language you are
using, of instructions "writing to a result tree", which sounds like a side
effect. XSLT 2.0 changed that - largely in response to a proposal from Jeni
Tennison - to a semantic model in which instructions return results; but the
term "instruction" was retained.
> 
>    The elements in an XSLT document can be executed in any 
> order, even in parallel.
> 
> Yesterday I thought that I had it all figured out: the 
> in-memory result tree can be constructed in any order, even 
> in parallel. However, from yesterday's responses, I am more 
> confused than before. Would you (or anyone) please explain 
> how the elements in an XSLT document can be executed in any 
> order, even in parallel?

Consider any expression that has subexpressions:

x() + y() + z()

x(), y(), z()

In each case the result of the final expression depends on the values of x,
y, and z, but (i) x(), y(), and z() do not depend on each other, and (ii)
evaluating x, y, or z has no side-effects; so in each case, it does not
matter what order x, y, and z are evaluated in.

In XSLT the construct

<a>
  <xsl:apply-templates select="x"/> 
  <xsl:apply-templates select="y"/> 
  <xsl:apply-templates select="z"/> 
</a>

is very like the second expression (x(), y(), z()). The three functions can
be evaluated in any order or in parallel. The results have to be assembled
in the correct order, but the evaluation does not need to be sequential.
This is quite different from a language such as Java, where you need to
evaluate x() before you evaluate y(), because evaluating x() can have
side-effects (such as updating global variables) that affect the result of
evaluating y().

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 


Current Thread
Keywords