Copying Elements from the Source Document to the Resultant Document
<xsl:copy> Element
copy-namespaces: Copies the namespace of the element in the source document to the resultant document. If the value of this attribute is yes, the namespace is copied to the resultant document. If this attribute has the value no, the namespace is not copied into the resultant document. The default value is yes.
use-attribute-sets: Copies attribute-sets while copying the element node to a resultant document. The qnames in the syntax are names of attribute-sets separated by spaces.
type, validation: Control the type annotation applied to individual elements and attribute nodes when a new node is created in the resultant document. The validation attribute has the following values:
strip: Indicates the type annotation, xs:anyType, if the new node created is an element node. Indicates the type annotation, xdt:unTypedAtomic, if the new node created is an attribute node. This attribute does not validate against the schema definition for the type annotation in the element and the attribute node.
preserve: Enables the newly constructed node in the resultant document to retain the type annotation as specified in the source document. The preserve value behaves differently depending on the type of the node created in the result document. For example, if the new node is an element node, the type annotation of the newly created node is xs:anyType. The nodes within the element retain the type annotation as specified in the source document. If the new node is an attribute node, the copied attribute retains the type annotation specified in the source document.
strict: Applies the type annotation to newly created nodes by validating the element or attribute nodes with the relevant schema definition declared in the source document. If the element or attribute node is not valid, transformation fails.
lax: Applies the type annotation to newly created nodes by validating the element or attribute nodes with the relevant schema definition declared in the source document. If the element or attribute is not valid, the type annotation for an element node is xs:anyType and for an attribute node is xdt:untypedAtomic.
Note
You need to specify the value of the version parameter as 2.0 because the copy-namespaces attribute is supported only in XSLT 2.0.
Types of Nodes | Function of the <xsl:copy> Element |
|---|---|
Root node | Creates an empty resultant document if the current node of the source document is the root node. The use-attribute-sets attribute of the <xsl:copy> element is ignored. |
Element node | Copies the element and the namespace of the corresponding element to the resultant document. This element does not copy child or descendant nodes. The use-attribute-sets attribute contains the list of attribute names added as the attribute of the new element node. |
Text node | Copies the content of the <xsl:text> element to the resultant document as displayed in the source document. The use-attribute-sets attribute of <xsl:copy> is ignored. |
Attribute node | Adds an attribute to the resultant document with the same name as that of the source document. If the <xsl:copy> element does not find an open element node, an error occurs. The use-attribute-sets attribute of the <xsl:copy> element is ignored. |
Processing Instruction node | Copies the node name and its value from the source document to the resultant document. |
Comment node | Copies the content of the comment node and the node name from the source document to the resultant document. |
Namespace node | Copies the namespace from the source document to the resultant document. To copy the namespace, the <xsl:copy> element needs to find an open element node. |
<xsl:copy-of> Element
In the above syntax:
select: Retrieves all nodes of the node-set and copies the nodes into the resultant document if the value of the expression is a node-set.
copy-namespaces: Copies the namespace to the resultant document if the copy-namespace attribute is set to yes. If you specify the value of this attribute as no, the namespace is not copied. Only XSLT 2.0 or later versions support this attribute.
validation: Is similar to the validation attribute of the <xsl:copy> element for all values, except the preserve value.
type: Enables a similar type annotation as that of the source document in the resultant document.
No comments:
Post a Comment