copy_1-input.xml
<?xml version="1.0"?>
<?myPI asdf234sd"?>
<products>
<!-- Delta -->
<product
id="p1" name="Delta" price="3250" stock="4"/>
<!-- Golf -->
<product
id="p2" name="Golf" price="1000" stock="5"/>
<!-- Alpha -->
<product
id="p3" name="Alpha" price="1200" stock="19"/>
</products>
copy_1-stylesheet.xsl
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output
indent="yes"/>
<xsl:template
match="@*|node()">
<xsl:copy>
<xsl:apply-templates
select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
copy_1-output.xml
<?xml version="1.0" encoding="UTF-8"?>
<?myPI asdf234sd"?>
<products>
<!-- Delta -->
<product
id="p1" name="Delta" price="3250" stock="4"/>
<!-- Golf -->
<product
id="p2" name="Golf" price="1000" stock="5"/>
<!-- Alpha -->
<product
id="p3" name="Alpha" price="1200" stock="19"/>
</products>
The stylesheet contains the "identity" template, the most important of all templates. It walks through the input document node for node and recreate them using xsl:copy. Attributes are also nodes but "node()" in the above context means all nodes being children of nodes that is: element(), comment() and processing-instruction(). For that reason we need a union also including attributes with "@*".
The identity template is normally modified with additional templates of exceptions. Because they match more precisely they overrule the identity template for some specific nodes. See my tutorial: Identity Template: xsl:copy with recursion.
Updated 2009-03-19