SGMLXML.net A place for SGML and XML application developers.

April 3, 2006

Create an Exact Copy of a Document using XSLT

Filed under: XSLT — cangione @ 1:59 pm







I get this request all the time so here is an example. It also shows you how to handle cases where you want to do something specific to certain elements while doing the copy.

<?xml version="1.0" encoding="UTF-8" ?>

<!--
    Document   : Create Copy of Document
    Created on : April 3, 2006
    Author     : sgmlxmldotnet
    Comment
       Demo file for Creating an Exact Copy of the document.
-->

<xsl:stylesheet version="1.0"
    xmlns:xsl=&quot;<a HREF="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</a>&quot;&gt;
    &lt;!-- template rule matching source root element --&gt;
    &lt;xsl:template match=&quot;/|*|comment()&quot;&gt;
       &lt;xsl:call-template name=&quot;do_copy&quot;/&gt;
    &lt;/xsl:template&gt;

&lt;!-- Add additional template matches here --&gt;

&lt;!-- Named Templates --&gt;
	&lt;!-- Copy current element and attribute nodes --&gt;
	&lt;xsl:template name=&quot;do_copy&quot;&gt;
	    &lt;xsl:copy&gt;
        	&lt;xsl:for-each select=&quot;@*&quot;&gt;
				&lt;xsl:copy/&gt;
			&lt;/xsl:for-each&gt;
			&lt;xsl:apply-templates/&gt;
        &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;


No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress