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: Fri, 16 Apr 2010 09:30:51 +0100
> The nodes are processed in 
> document order, unless a sorting specification is present 
> (see [10 Sorting])."
> 
> So, in XSLT 1.0 there is order of processing (at least in the case of
> <xsl:for-each/>) and it is explicitly specified.

XSLT 1.0 often used rather informal language like this; XSLT 2.0 took great
pains to avoid unwanted implications suggested by this kind of language.
That's probably why XSLT 1.0 was written in a year, while XSLT 2.0 took
seven years.

There is no way in XSLT 1.0 of telling what the actual order of evaluation
is, and therefore a statement in the spec that suggests a particular order
has no force. Processors are conformant if they produce the right results in
all circumstances, whether or not they do things the way the spec suggests
they should be done.

I'm sure the intent of the XSLT 1.0 spec was to say that xsl:for-each
defines a function F (its template body) that maps nodes in the input
sequence I to nodes in the output sequence O, and the result of the
xsl:for-each instruction is O = map(F, sort(I)) where sort is a function
that sorts a set of nodes into a sequence of nodes in document order.

> However, I don't know what the following text from the XSLT 
> 2.0 Specification means (does it mean that in many cases 
> there is still prescribed order of processing?):
> http://www.w3.org/TR/xslt20/#for-each
> 
> "Note:
> 
> With XSLT 1.0, the selected nodes were processed in document order.
> With XSLT 2.0, XPath expressions that would have been valid 
> under XPath 1.0 (such as path expressions and union 
> expressions) will return a sequence of nodes that is already 
> in document order, so backwards compatibility is maintained."

The note is trying to explain how the apparently different specifications
for 1.0 and 2.0 actually deliver the same result. Notes are informal and
intended to aid understanding; if you don't find them useful, you can ignore
them.

In this particular case the burden of sorting nodes into document order fell
on XSLT in the 1.0 specification, but falls on XPath in the 2.0 spec.

Regards,

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

Current Thread