[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: The output of evaluating an XSLT transform is the

Subject: RE: 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 21:53:20 +0100
RE:  The output of evaluating an XSLT transform is the
> Given the following source XML  document and a data-driven (push
> style) XSLT transformation:
> <a1>
>  <a2>
>    <a3>
>      <a4/>
>    </a3>
>  </a2>
> </a1>
> then the start of processing <a{N}> will be after the start 
> of processing of <a{N-1}>.

As far as the language semantics are concerned, a4 is a subexpression of a3
and is therefore evaluated first. Evaluation of a4 produces an element node;
evaluation of a3 copies this element node to create the child of the new a3
element. Evaluation of a2 then copies the new a3, and so on. So contrary to
your description, evaluation of a4 happens BEFORE a3.

Now a real XSLT processor might behave quite differently. Saxon, for
example, might compile this into a sequence of internal instructions:

emit startElement(a1)
emit startElement(a2)
emit startElement(a3)
emit startElement(a4)
emit endElement(a4)
emit endElement(a3)
emit endElement(a2)
emit endElement(a1)

This is sufficiently far removed from the abstract syntax tree that to ask
what order the source expressions are evaluated in is not very meaningful.
It becomes even less meaningful once you have some real expressions to
compute the names and content of the elements. For example, if the logic

<xsl:template match="x">
  <xsl:variable name="this" select="."/>
  <a1 name="{concat($p, 1)}">
     <xsl:for-each select="*">
       <a2 name="{concat($p, $this/@id)}"/>

then the expression concat($p, 1) will be turned into a global variable that
is computed once, the first time it is used, while the expression concat($p,
$this/@id) will be calculated once, during the first iteration of the
xsl:for-each loop.


Michael Kay

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.