Share via


xsl:copy-of Element (Windows Embedded CE 6.0)

1/6/2010

Inserts subtrees and result-tree fragments into the result tree.

Syntax

<xsl:copy-of
  select = expression />

Attributes

  • select
    [required] XPath expression identifying nodes to be copied. The subtree below each of these nodes is copied to the result tree in its entirety.

Element Information

Number of occurrences

Unlimited

Parent elements

xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:for-each, xsl:if, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements

Child elements

(No child elements)

Remarks

When the result of evaluating the expression is a result-tree fragment, the complete fragment is copied into the result tree. When the result is a node-set, all the nodes in the set are copied in document order into the result tree; copying an element node copies the attribute nodes, name space nodes, and children of the element node as well as the element node itself. A root node is copied by copying its children. When the result is neither a node-set nor a result-tree fragment, the result is converted to a string and then inserted into the result tree, as with <xsl:value-of>.

Example

Given this XML,

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="family.xsl"?>
<family>
  <person>
    <given-name age="10">
      <name>James</name>
      <nick-name>Jim</nick-name>
    </given-name>
    <family-name>Fine</family-name>
  </person>
  ...
</family>

the following transform finds a person element with "given-name" and "family-name" children elements. The paragraph will contain the first "given-name" child element of the current node, including any attributes and child elements, followed by a space and the first "family-name" child element, including any attributes and child elements, of the current node.

<xsl:template match="person">
  <p>
    <xsl:copy-of select="given-name"/>
    <xsl:text> </xsl:text>
    <xsl:copy-of select="family-name"/>
  </p>
</xsl:template>

The generated HTML is as follows:

<?xml version="1.0" encoding="UTF-16"?>
<p>
  <given-name age="10">
    <name>James</name>
    <nick-name>Jim</nick-name>
  </given-name>
  <family-name>Fine</family-name>
</p>

See Also

Reference

XSLT Elements
xsl:value-of Element