XSLT 1.1 was withdrawn but in this respect XSLT 2.0 is the same.
 
v1a is a root node (known in XSLT 2.0 as a document node). v2a is an element node, the <a> element. The document node is the parent of the <a> element. When you use xsl:copy-of to create the content of an element, a document node cannot be a child of an element, so the children of the document node are copied instead. So copying the document node has exactly the same effect as copying its children: in this case, there is only one child, the <a> element.
 
However, doing apply-templates on $v1a will not produce the same result as apply-templates on $v2a.
 
Michael Kay
 

From: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net] On Behalf Of Cary Millsap
Sent: 26 July 2004 20:21
To: saxon-help@lists.sourceforge.net
Subject: [saxon] temporary trees and xsl:copy-of

Greetings:

 

I have a question that’s been bothering me for a long time. My understanding of how variables and parameters work in XSLT 1.1  is all goofed up. I do not understand why the stylesheet shown below produces the output it does. In particular, I’m confused about why the values of v1a and v1b are apparently identical.

 

Thank you in advance.

 

Cary Millsap

 

Stylesheet

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.1" xmlns:xsl=http://www.w3.org/1999/XSL/Transform exclude-result-prefixes="xsl">

            <xsl:output method="xml" version="1.0" encoding="UTF-8" omit-xml-declaration="no" indent="yes" media-type="text/xml"/>

           

            <xsl:template match="/">

                        <xsl:variable name="v">

                                    <xsl:element name="a">

                                                <xsl:element name="b">

                                                            <xsl:element name="c"/>

                                                </xsl:element>

                                                <xsl:element name="b"/>

                                    </xsl:element>

                        </xsl:variable>

                       

                        <xsl:variable name="v1a"><xsl:call-template name="transform1"><xsl:with-param name="v" select="$v"/></xsl:call-template></xsl:variable>

                        <xsl:variable name="v1b"><xsl:call-template name="transform1"><xsl:with-param name="v" select="$v/*"/></xsl:call-template></xsl:variable>

                        <xsl:variable name="v1c"><xsl:call-template name="transform1"><xsl:with-param name="v" select="$v/*/*"/></xsl:call-template></xsl:variable>

                        <xsl:variable name="v1d"><xsl:call-template name="transform1"><xsl:with-param name="v" select="$v/*/*/*"/></xsl:call-template></xsl:variable>

                        <v1a><xsl:copy-of select="$v1a"/></v1a>

                        <v1b><xsl:copy-of select="$v1b"/></v1b>

                        <v1c><xsl:copy-of select="$v1c"/></v1c>

                        <v1d><xsl:copy-of select="$v1d"/></v1d>

                       

                        <xsl:variable name="v2a"><xsl:call-template name="transform2"><xsl:with-param name="v" select="$v"/></xsl:call-template></xsl:variable>

                        <xsl:variable name="v2b"><xsl:call-template name="transform2"><xsl:with-param name="v" select="$v/*"/></xsl:call-template></xsl:variable>

                        <xsl:variable name="v2c"><xsl:call-template name="transform2"><xsl:with-param name="v" select="$v/*/*"/></xsl:call-template></xsl:variable>

                        <xsl:variable name="v2d"><xsl:call-template name="transform2"><xsl:with-param name="v" select="$v/*/*/*"/></xsl:call-template></xsl:variable>

                        <v2a><xsl:copy-of select="$v2a"/></v2a>

                        <v2b><xsl:copy-of select="$v2b"/></v2b>

                        <v2c><xsl:copy-of select="$v2c"/></v2c>

                        <v2d><xsl:copy-of select="$v2d"/></v2d>

            </xsl:template>

           

            <xsl:template name="transform1">

                        <xsl:param name="v"/>

                        <xsl:copy-of select="$v"/>

            </xsl:template>

           

            <xsl:template name="transform2">

                        <xsl:param name="v"/>

                        <xsl:copy-of select="$v/*"/>

            </xsl:template>

           

</xsl:stylesheet>

 

Output (blank lines added for clarity)

<?xml version="1.0" encoding="UTF-8"?>

<v1a>

   <a>

      <b>

         <c/>

      </b>

      <b/>

   </a>

</v1a>

 

<v1b>

   <a>

      <b>

         <c/>

      </b>

      <b/>

   </a>

</v1b>

 

<v1c>

   <b>

      <c/>

   </b>

   <b/>

</v1c>

 

<v1d>

   <c/>

</v1d>

 

 

<v2a>

   <a>

      <b>

         <c/>

      </b>

      <b/>

   </a>

</v2a>

 

<v2b>

   <b>

      <c/>

   </b>

   <b/>

</v2b>

 

<v2c>

   <c/>

</v2c>

 

<v2d/>