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

Re: Trying to understand root-less or document-node-le

Subject: Re: Trying to understand root-less or document-node-less nodes
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 18 Sep 2007 08:39:45 +0200
Re:  Trying to understand root-less or document-node-le
David Carlisle wrote:
<xsl:variable name="y2">
<xsl:copy-of select=$x/x/b"/>
</xsl:variable>

I assume, in light of the rest you told, that consequently the same statement with xsl:sequence will yield a copy, instead of the expected reference (which would happen when you specified the as="element()*"). A reason more for being explicit about it in the code.



<xsl:variable name="y3" as="element()"> <xsl:sequence select=$x/x/b"/> <foo/> <xsl:sequence select=$x/x/c"/> </xsl:variable>


is a sequence of 5 elements two bs, a foo and a c, but note that teh b's
and c's are siblinngs of each other (and all are siblings of $x/x/a) but that
<foo/> is a new parentless element not a sibling of anything.

This is like a good textbook example. Brilliant, this single thing makes it clear how sequences and nodes interact with one another and how it can yield crazy and unexpected results to the unaware. By using <xsl:sequence> the distinction is made clearer. So, basically, from a programming standpoint, one has to ask oneself: do I want to break from my ancestors (xsl:copy) or do I want to keep the navel-string intact (xsl:sequence or select attribute). And in all cases: make explicit what you want.



xsl:function (and xsl:template, xsl:if and several other instructions) work like xsl:variable with as="item()". That is, their content generates a sequence which is returned as the value of the instruction. xsl:variable (and xsl:param) without an as attribute generate a sequence in the same way, but then as an additional step generate an implict document node and _copy_ the generated sequence as children of that node (which implies generating text nodes corresponding to any atomic values in the sequence)

Though I was aware of the fact that xsl:variable/param creates document nodes, even when you simply have <xsl:variable>text</xsl:variable> and that it is an expensive trade off, I never realized why, or the reason behind it. This clearly is a statement and/or a discussion to make it explicit with an 'as' clause, because the implicit rules are too different between functions and variables.


Thanks David, for the clear rundown of the matter.

Cheers,
-- Abel Braaksma

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.