[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: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Mon, 07 Oct 2002 23:53:17 +0200
xsl add an element
Hi Lynda,

don't differentiate between <MessageID> and </MessageID>. Of course there is a difference, because the one opens an element, the other closes it, but they absolutely belong together. Your sentence

> I need just of copy of the element <MessageID> following the source
> <MessageID> and </Message> following the source </MessageID>

expressed in a way a bit more XSLT or XPath: you want to have a *nested* <MessageID/>. Or as *child* of a <MessageID/> *element*, you want to have a second <MessageID/>.

With the templates I already sent, it's really easy. Change the second one two:

<xsl:template match="MessageID">

If <MessageID/> has any attribute, you can change the template to:

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

See the both ways to get all attributes copied. The second one does only work because of the identity transformation template.

May I ask, why you need the nested <MessageID/> elements? It looks a bit strange.



LVanvleet@xxxxxxxxxx wrote:
Thanks for your timely reply.  I understand you technique but that puts an
entire duplicate<MessageID>...</MessageID> following the current
I need just of copy of the element <MessageID> following the source
<MessageID> and </Message> following the source </MessageID>
Sorry I wasn't very clear.

-----Original Message-----
From: Joerg Heinicke [mailto:joerg.heinicke@xxxxxx]

Hello Lynda,

hmm, I are copying in the wrong way. From the root context you are copying everything, you should copy node by node. You can read at http://www.w3.org/TR/xslt#copying how identity transformation can look like:

<xsl:template match="@*|node()">
     <xsl:apply-templates select="@*|node()"/>

Then you only need to add further template matching on <MessageID/> and say there, that you want to have it twice in the output:

<xsl:template match="MessageID">
     <xsl:apply-templates select="@*|node()"/>
     <xsl:apply-templates select="@*|node()"/>



LVanvleet@xxxxxxxxxx wrote:

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>

I am using this XSLT:

<?xml version='1.0'?>
<xsl:transform version="1.0"
<xsl:output method="xml" indent="yes"/>

<!-- copy all the elements to the result document -->
<xsl:template match="/">
	<xsl:copy-of select="."/>

<xsl:template match="Order">

<xsl:template match="//ListOfMessageID/MessageID">
<!-- add an extra <MessageID> and </MessageID> element -->
<xsl:element name="MessageID"/>
<xsl:apply-templates select="node()"/>

On a document that starts with the elements:

<?xml version="1.0"?>
<!-- Exostar xCBL 3.0 Order ICD -->

Lynda Van Vleet

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

Current Thread


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.
First Name
Last Name
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.