<xsl:copy> Element

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XSLT Reference

<xsl:copy> Element

Copies the current node from the source to the output.

<xsl:copy
  use-attribute-sets = QNames >
</xsl:copy>

Attributes

use-attribute-sets
A white space separated list of attribute sets, specified as a qualified name. A white space separated list of attribute sets, specified as a qualified name. Specifying this attribute declares each attribute in each listed attribute set.

Element Information

Remarks

The <xsl:copy> element creates a node in the output with the same name, namespace, and type as the current node. Attributes and children are not copied automatically. This element makes identity transformation possible.

Example

The following example performs an identity transformation on an entire document. The identity transformation copies each node in the source to the output to provide a logically equivalent tree. It does not yield character-by-character equivalence: Entities will be expanded, and white space not marked as significant might be removed.

Note To test this example, you need to use a script. For more information, see Initiate XSLT in a Script.

XML File (booksshort.xml)

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="identityxfm.xsl"?>
<catalog>
    <book id="bk101">
        <author>Gambardella, Matthew</author>
        <title>XML Developer's Guide</title>
        <genre>Computer</genre>
        <price>44.95</price>
        <publish_date>2000-10-01</publish_date>        
        <description>An in-depth look at creating applications with
 XML.</description>
    </book>
    <book id="bk102">
        <author>Ralls, Kim</author>
        <title>Midnight Rain</title>
        <genre>Fantasy</genre>
        <price>5.95</price>
        <publish_date>2000-12-16</publish_date>
        <description>A former architect battles corporate zombies,
 an evil sorceress, and her own childhood to become queen of the
 world.</description>
    </book>
    <book id="bk103">
        <author>Corets, Eva</author>
        <title>Maeve Ascendant</title>
        <genre>Fantasy</genre>
        <price>5.95</price>
        <publish_date>2000-11-17</publish_date>
        <description>After the collapse of a nanotechnology society
 in England, the young survivors lay the foundation for a new 
society.</description>
    </book>
</catalog>

XSLT File (identityxfm.xsl)

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

  <xsl:template match="/ | @* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Output

This is a portion of the formatted output, truncated on the right side:

Gambardella, MatthewComputer44.952000-10-01An in-depth look
and her own childhood to become queen of the world.Corets, EvaFa

This is the processor output:

<?xml version="1.0"?><?xml-stylesheet type="text/xsl" 
href="identityxfm.xsl"?><catalog><book id="bk101"><author>Gambardella, 
Matthew</author><title>XML Developer's 
Guide</title><genre>Computer</genre><price>44.95</price><publish_date>2000
-10-01</publish_date><description>An in-depth look at creating 
applications with
 XML.</description></book><book id="bk102">
...
</book></catalog>

See Also

Generating Comments, Processing Instructions, and Elements