Quick References
      ADO
      ASP
      CSS2
      HTML
      JavaScript
      Jet SQL
      VBScript
      WML
      WMLScript
      WSH
      XHTML
      XML DOM
      XSLT

Features
      Knowledge Base
      Tutorials

Partners
     ZVON.ORG
     XML
     Planet Source Code
     VisualBuilder
     Web Design
     Your HTML Source
     XML/XSLT Forums
     ASPAlliance
     Scripts
     
     Programmers Heaven
     Tek-Tips Forums
     Developer Fusion
     Code Project


   







ELEMENT:  xsl:copy-of

<xsl:copy-of
  select="expression"
/>

 
The xsl:copy-of element inserts a duplicate copy of a node set or tree fragment into the output. Perhaps the most important aspect of this element is that it allows you to insert multiple copies of the same set of nodes into different places in the output. For example, you may wish to repeat a page header.
 
When a node set is copied, the nodes will be copied into the output in their order of occurrence in the source (this is referred to as document order). Each node and all associated attribute nodes, namespace nodes, children and descendants are copied. In other words, it is a complete, unabridged copy of the set.
 
When a root node is copied, all of the children and descendants are copied, but not the root node itself since there can only be one root.
 
When a tree fragment is copied, it is copied exactly to the output.
 
For all other circumstances, the xsl:copy-of element behaves exactly like the xsl:value-of element. The value being copied is converted into a string for display in the output.
 
In contrast, the xsl:copy element copies the current node in the source document to the output. The copy has the same name, namespace, and type as the original node, but any attributes, children, and other descendants are not copied.
 
This is a self-closing element and it cannot contain any child elements or any content.
 
select="expression"
 
The mandatory select attribute is an expression that identifies which nodes are to be copied.
 
We use the DevGuru Staff List XML file for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_copyof.xsl"?>
and we name it: xslt_example_copyof.xml
 
In this example, we repeat the table header in two different tables.
 
Code for xslt_example_copyof.xsl:
 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="staff_table">
<tr>
<td><b>Name</b></td>
<td><b>Age</b></td>
</tr>
</xsl:variable>
<xsl:template match="/">
<html>
<body>
<table>
<xsl:copy-of select="$staff_table" />
<xsl:for-each select="devguru_staff/programmer">
<tr>
<xsl:if test="age &lt; 35">
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="age" /></td>
</xsl:if>
</tr>
</xsl:for-each>
</table>
<p />
<table>
<xsl:copy-of select="$staff_table" />
<xsl:for-each select="devguru_staff/programmer">
<tr>
<xsl:if test="age &gt; 34">
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="age" /></td>
</xsl:if>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

 
Output:
 
Click to view output in separate window - requires Internet Explorer

 
 


Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information