Inserts sub-trees and result tree fragments into the result tree.
<xsl:copy-of select = expression/>
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) |
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, namespace 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>.
Given this XML,
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="family.xsl"?> <family> <person> <given-name age="10"> <name>Fred</name> <nick-name>Freddy</nick-name> </given-name> <family-name>Smith</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>Fred</name> <nick-name>Freddy</nick-name> </given-name> <family-name>Smith</family-name> </p>