<?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet href="../make-menu.xsl" type="text/xsl"?><html> <head> <this-is section="xsl-elements" page="copy" subpage=""/> <!-- Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: xsl:copy</title> <meta name="coverage" content="Worldwide"/> <meta name="copyright" content="Copyright Saxonica Ltd"/> <meta name="title" content="Saxonica: XSLT and XQuery Processing: xsl:copy"/> <meta name="robots" content="noindex,nofollow"/> <link rel="stylesheet" href="../saxondocs.css" type="text/css"/> </head> <body class="main"> <h1>xsl:copy</h1> <p>The <code>xsl:copy</code> element causes the current XML node in the source document to be copied to the output. The actual effect depends on whether the node is an element, an attribute, or a text node.</p> <p>For an element, the start and end element tags are copied; the attributes, character content and child elements are copied only if <code>xsl:apply-templates</code> is used within <code>xsl:copy</code>.</p> <p>Attributes of the generated element can be defined by reference to a named attribute set. The optional use-attribute-sets attribute contains a white-space-separated list of attribute set names. They are applied in the order given: if the same attribute is generated more than once, the later value always takes precedence.</p> <p>The following example is a template that copies the input element to the output, together with all its child elements, character content, and attributes:</p> <div class="codeblock" style="border: solid thin; background-color: #B1CCC7; padding: 2px"> <pre> <code><xsl:template match="*|text()|@*"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> </code> </pre> </div> <p>In XSLT 3.0, a new <code>select</code> attribute is added to <code>xsl:copy</code>, allowing a node other than the context node to be copied. This is useful when the instruction appears inside <code>xsl:function</code>.</p> <table width="100%"> <tr> <td> <p align="right"><a class="nav" href="copy-of.xml">Next</a></p> </td> </tr> </table> </body> </html>