1. Technology

What is XSL Copy-of

XSL Copy-of Definition

By

Definition: The xsl:copy-of element repeats the current node in the XSLT output stream along with any attributes or child elements that come with it. In other words, if you have an element in your source document, you can repeat it and all the trimmings in the output stream. XSL offers two copy tags; xsl:copy and xsl:copy-of. The difference between the two comes in the attributes and child elements of your node. With 'xsl:copy' you only repeat the parent element. XSL:copy-of is an extension of 'copy.' It will repeat the parent element plus any child elements and attributes that are part of the node. This allows you to separate the child elements within the parent node using the 'select' attribute.

Extension: .xsl

Syntax: xsl:copy-of

Associated Elements:

  • xsl:copy
  • select

Sample

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="catalog">
<xsl:copy-of select="bikes"/>
</xsl:template>
</xsl:stylesheet>

Code Breakdown

List the declaration statement for a XML document.

<?xml version="1.0"?>

Add the root element for a style sheet with the XSLT namespace.

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

The parent element is 'xsl:template.' This identifies a template for the parser.

<xsl:template match="/">

The match attribute is a XPath expression that points to the element in the XML code where the formatting rules apply. The 'match="catalog"' attribute instructs the parser to look for the node titled 'catalog and to repeat it in the output stream.

The 'xsl:copy-of' element instructs the parser to list the all the code and data under the element 'bikes' in the output stream. Copy-of can be utilized in sorting and for-each functions that help apply specific rules to the output created. After you complete the copy statement, close all open tags.

</xsl:template>
</xsl:stylesheet>
  1. About.com
  2. Technology
  3. Web Design / HTML
  4. XML
  5. XSLT
  6. Definition of the XSL Copy-of Element

©2014 About.com. All rights reserved.