xsl:copy-of

  1. copy-of_1-input.xml

  2. <?xml version="1.0"?>
  3. <products>
  4.   <product id="p1">
  5.     <name>Delta</name>
  6.     <stock>4</stock>
  7.   </product>
  8. </products>
  1. copy-of_1-stylesheet.xsl

  2. <?xml version="1.0"?>
  3. <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4.   <xsl:output indent="yes"/>
  5.   <xsl:template match="/">
  6.     <catalog>
  7.       <xsl:copy-of select="products/product"/>
  8.     </catalog>
  9.   </xsl:template>
  10. </xsl:stylesheet>
  1. copy-of_1-output.xml

  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <catalog>
  4.   <product id="p1">
  5.     <name>Delta</name>
  6.     <stock>4</stock>
  7.   </product>
  8. </catalog>

Comment

The element xsl:copy-of is a deep copy, copying the context element with atttibutes and children elements and their children and attributes, etc. also comments and processing-instructions are copied.

Updated 2009-03-19