[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Add an element to the result xml document

Subject: RE: Add an element to the result xml document
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Tue, 8 Oct 2002 09:58:27 +0100
xslt copy entire document
> I have sucessfully copied all the elements in source xml to 
> result xml but I also want duplicates of some elements.  In 
> the partial xml doc below I want the result to contain two 
> copies of the <MessageID> and </MessageID> elements.
> 
> I am using this XSLT:
> 
> <!-- copy all the elements to the result document --> 
> <xsl:template match="/">
> 	<xsl:copy-of select="."/>
> </xsl:template>

Anything else in your stylesheet is irrelevant. You come in at the root
node, you copy the entire source tree to the output, and you exit. The
simplest transformation there is. Not hard to be successful at that one!

If you want to do anything other that a straight copy, the first thing
to do is to get rid of the <xsl:copy-of> and write
<xsl:apply-templates>. Then you can start writing template rules that
describe how you want each node to be processed. By default you probably
want nodes unchanged, so write

<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

and then add template rules for any nodes which you don't want to copy
exactly.

For example (I can't see why you would want to do this):

<xsl:template match="MessageID">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
<!-- and again... -->
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.