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 21:53:20 +0100 |
> 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 were: <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. Regards, Michael Kay http://www.saxonica.com/ http://twitter.com/michaelhkay
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] The output of evaluating , Dimitre Novatchev | Thread | Re: [xsl] The output of evaluating , Dimitre Novatchev |
Re: [xsl] The output of evaluating , Dimitre Novatchev | Date | Re: [xsl] The output of evaluating , David Carlisle |
Month |