xsl:copy
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.
Category: instruction
Content: sequence-constructor
Permitted parent elements:
any XSLT element whose content model is
sequence-constructor; any literal result element
Attributes
|
| New in XSLT 3.0. Allows a node other than the context node to be copied. This is useful when the instruction appears inside xsl:function. |
|
| Used only when copying element
nodes. If the value is |
|
| Used only when copying element
nodes. If the value is |
|
| Used only when copying element nodes. Attributes of a generated element can be defined by reference to named attribute sets, provided as a whitespace-separated list. They are applied in the order given: if the same attribute is generated more than once, the later value always takes precedence. |
|
| Requests validation of the constructed node against a specified XSD type. The value will typically be a user-defined complex type defined in an imported schema. |
|
| Requests strict or lax validation of the contents of the constructed node against the element declaration of its top-level element. |
Saxon availability
Available in XSLT 1.0 and later versions. Available in all Saxon editions. Available for all platforms.
Notes on the Saxon implementation
Modivated by streaming, the on-empty
attribute was introduced in an
early Working Draft for XSLT 3.0, but later removed and replaced by the new xsl:on-empty, xsl:on-non-empty and xsl:where-populated
instructions. The on-empty
attribute was implemented in Saxon 9.5,
but removed in 9.7.
Details
When xsl:copy
is applied to an element node, the start and end
element tags are copied; the attributes, character content and child elements
are copied only if xsl:apply-templates is used within xsl:copy
.
Examples
A template that copies the input element to the output, together with all its child elements, character content, and attributes:
<xsl:template match="*|text()|@*"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template>