[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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

Subject: [xsl] Re: XSLT 2.0: On xsl:sequence and xsl:copy-of
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Fri, 10 Oct 2003 21:52:23 +0200

> > 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.

That means xsl:reference describes all of these cases.

> >
> >
> >   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
> things.

Yes, but when we'll need a copy of a node and having a reference will not

Using a copy may make sense if what is copied could change in time -- but
XSLT is a functional language and this is not possible.

> >
> >   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.

I think that many people in this list would be interested to have a look
too. Could you, please, give us such an example whenever you have the time?

> >
> >   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.

Then a slight modification:

    <xsl:variable name="v1" as="item()*">
      <xsl:sequence select="/"/>
    <xsl:variable name="v2"  as="item()*">
      <xsl:sequence select="/"/>

    <xsl:copy-of select="$v1 except $v2"/>

I guess this will not produce any output -- am I right?

My last question is the following:

In the example above the two sequences consist not of nodes, but of
*references to nodes*. This is a very useful new datatype, not present in
the XPath data model. Will it not be nice to explain this in detail in the
XSLT spec.?


Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread