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

select?

expression

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.

copy-namespaces?

boolean

Used only when copying element nodes. If the value is yes (the default), then all namespace nodes of the source element are copied as namespace nodes for the newly constructed element. If the value is no, then the namespace nodes are not copied.

inherit-namespaces?

boolean

Used only when copying element nodes. If the value is yes (the default), then the namespace nodes created for the newly constructed element are copied to its children and descendants. If the value is no, then these namespace nodes are not automatically copied.

use-attribute-sets?

eqnames

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.

type?

eqname

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.

validation?

"strict" | "lax" | "preserve" | "strip"

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>

Links to W3C specifications

XSLT 2.0 Specification

XSLT 3.0 Specification

See also

xsl:copy-of