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="http://www.w3.org/1999/XSL/Transform">
    <!-- template rule matching source root element -->
    <xsl:template match="/|*|comment()">
       <xsl:call-template name="do_copy"/>
    </xsl:template>

<!-- Add additional template matches here -->

<!-- Named Templates -->
	<!-- Copy current element and attribute nodes -->
	<xsl:template name="do_copy">
	    <xsl:copy>
        	<xsl:for-each select="@*">
				<xsl:copy/>
			</xsl:for-each>
			<xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>


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