xsl:copy
Creates a shallow copy of the current node — for an element, that means a new element with the same name and namespace, but no children or attributes. The body of xsl:copy then populates the copy.
<xsl:copy>
...
</xsl:copy>xsl:copy is the building block of identity transforms: combined with a recursive xsl:apply-templates, it walks a tree and reproduces it exactly, allowing other templates to override the handling of specific nodes. For deep copies (copying nodes with their descendants and attributes), use xsl:copy-of instead.
Attributes
| Attribute | Description |
|---|---|
copy-namespaces |
yes (default) or no — whether to copy in-scope namespaces of the source element. |
inherit-namespaces |
yes (default) or no — whether the copy inherits namespaces from its parent in the result tree. |
use-attribute-sets |
Space-separated list of attribute set names to apply. |
Example
The classic identity transform:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>Override one element while keeping the rest unchanged:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="price">
<xsl:copy>
<xsl:value-of select=". * 1.19"/>
</xsl:copy>
</xsl:template>