XSLT » Elements » xsl:copy


The xsl:copy element copies the current node in the source document to the output. The copy has the same name, namespace, and type as the original node, but any attributes, children, and other descendants are not copied. (Note that you can apply this element recursively to copy attributes and children.)

The xsl:copy-of element can be used to copy a node set. Children are copied with this element.
A common use of this element is to make identity transformations.


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/ | @* | node()">
<xsl:apply-templates select="@* | node()" />
<?xml version="1.0" encoding="UTF-16"?>
<?xml-stylesheet type="text/xsl" href="xslt_example_copy.xsl"?>
      <name>Bugs Bunny</name>
      <address>4895 Wabbit Hole Road</address>
      <name>Daisy Duck</name>
      <address>748 Golden Pond</address>
      <name>Minnie Mouse</name>
      <address>4064 Cheese Factory Blvd</address>
      <address>414 Dog Lane</address>
      <name>Porky Pig</name>
      <address>555 Mud Pit Pike</address>
      <name>Road Runner</name>
      <address>135 Desert View Street</address>

For our example, we display the standard code for making an identity transformation. This is the code for xslt_example_copy.xsl.
We use the DevGuru Staff List XML file for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_copy.xsl"?>

Language(s): XSLT

See Also: