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

inherit-namespaces?

boolean

use-attribute-sets?

eqnames

Attributes of a generated element can be defined by reference to named attribute sets, provided as a white-space-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

validation?

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

on-empty?

expression

New in XSLT 3.0, motivated by streaming. Expression which defines an alternative result in the case where the copied element would otherwise be empty. The most likely value is on-empty="()", which means that empty elements are not written.

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