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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--