RE: [xsl] XSLT 2.0: On xsl:sequence and xsl:copy-of

Subject: RE: [xsl] XSLT 2.0: On xsl:sequence and xsl:copy-of
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 10 Oct 2003 20:05:35 +0100
>   O1. The name xsl:sequence is not the best possible name for 
> this xslt instruction.

Yes, we know. But we've failed to come up with anything better. I think
we would go for xsl:value if it were not for the confusion with
xsl:value-of which is not a very good name for an instruction that
produces a text node, but we're stuck with it. 

> Now that everything is a sequence in 
> XPath 2.0, the word sequence has become a buzz word and its 
> overuse (not to say misuse) can only lead to confusion. If 
> the result of this instruction is placing references to nodes 
> in the output, then a more exact name would be one of the
> following:
>     xsl:reference
>     xsl:add-reference
>     xsl:node-reference

None of these are suitable, because xsl:sequence can produce any
sequence of nodes and/or atomic values.
>   O2. xsl:sequence does everything that can be done with 
> xsl:copy-of and these two xslt instructions are mutually redundant.

There is certainly an overlap. With atomic values, they do the same
thing. And it's true that in some contexts, nodes returned be
xsl:sequence are going to get copied anyway, to add them to a new tree.
But returning a node and making a copy of a node are rather different
>   Q1. Is there anything that can be accomplished with 
> xsl:copy-of and which cannot be accomplished by using xsl:sequence?

At this time of a Friday night, I can't immediately recall what the use
case was. Some of the examples we looked at involved validation.
>   Q2. Is there any compelling reason of keeping xsl:copy-of 
> in the language (apart for compatibility with XSLT 1.0)?

See above.
>   Q3. Let's have:
>     <xsl:variable name="v1">
>       <xsl:sequence select="/"/>
>     </xsl:variable>
>     <xsl:variable name="v2">
>       <xsl:sequence select="/"/>
>     </xsl:variable>
>     <xsl:copy-of select="$v1 except $v2"/>
> Should the output of this code be empty or not? If not, what 
> should the output be?

xsl:variable without an "as" attribute constructs a temporary tree, so
in this context xsl:sequence has the same effect as xsl:copy-of. You are
constructing two different trees containing distinct nodes, so ($v1
except $v2) returns $v1.

Michael Kay

 XSL-List info and archive:

Current Thread