Microsoft XML 2.5 SDK


 

xsl:copy Element

[This is preliminary documentation and subject to change.]

Copies the current node from the source to the output.

Syntax

<xsl:copy  >

</xsl:copy>

Element Information

Number of occurrences Unlimited
Parent elements xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:for-each, xsl:if, xsl:otherwise, xsl:pi, xsl:template, xsl:when, output elements
Child elements xsl:apply-templates, xsl:attribute, xsl:choose, xsl:comment, xsl:copy, xsl:element, xsl:eval, xsl:for-each, xsl:if, xsl:pi, xsl:value-of, output elements
Requires closing tag Yes. XSL is an XML grammar and, like all XML grammars, all tags must have closing tags to satisfy the definition of well-formed.

Remarks

The xsl:copy element creates a node in the output with the same name, namespace, and type as the current node. Attributes and children are not copied automatically. This element makes identity transformation possible.

Example

The following example performs an identity transform on the entire document. The identity transform copies each node in the source to the output to provide a logically equivalent tree. It does not yield character-by-character equivalence—entities will be expanded, white space not marked as significant may be removed.

Note   This example is formatted for readability and might introduce unwanted white space during the transformation. To eliminate this extra white space, remove the indentations and carriage returns between the xsl elements within the template.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
  <xsl:template>
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

See Also

Generating More Sophisticated XML Output, Filtering XML, Copying Entire Subtrees