Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 15th, 2013, 06:51 AM
Authorized User
 
Join Date: Mar 2013
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Appending a node to existing XML

Hello all,

I want to append a node to an existing xml.
the existing xml is as follows...
<Transmission>
<ItemMaster>
<Item>
<ItemId>111</ItemId>
<ItemName>I1</ItemName>
</Item>
<Item>
<ItemId>112</ItemId>
<ItemName>I2</ItemName>
</Item>
<Item>
<ItemId>113</ItemId>
<ItemName>I3</ItemName>
</Item>
</ItemMaster>
</Transmission>
Now I want to add anew node to existing xml as follows,
<Location>
<LocId>l1</LocId>
<LocName>loc aaa</LocName>
</Location>

So by appending the location node to existing xml now my xml should look like this....

<Transmission>
<ItemMaster>
<Item>
<ItemId>111</ItemId>
<ItemName>I1</ItemName>
</Item>
<Item>
<ItemId>112</ItemId>
<ItemName>I2</ItemName>
</Item>
<Item>
<ItemId>113</ItemId>
<ItemName>I3</ItemName>
</Item>
</ItemMaster>
<Location>
<LocId>l1</LocId>
<LocName>loc aaa</LocName>
</Location>
<Location>
<LocId>l2</LocId>
<LocName>loc bbb</LocName>
</Location>
</Transmission>


Can anybody help me to resolve the issue...


Thanks in advance!!!!!!!!

Sarala
 
Old March 15th, 2013, 08:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This is about as simple a transformation as one can write. I'm surprised you found it difficult.

Code:
<xsl:template match="Transmission">
<Transmision>
  <xsl:copy-of select="*"/>
  <Location>
    <LocId>l1</LocId>
    <LocName>loc aaa</LocName>
  </Location>
</Transmission>
</xsl:template>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to append node to an existing file geek.shrek XSLT 4 January 10th, 2010 02:08 PM
Adding a node to an existing xml node list. codehelp C# 2008 aka C# 3.0 2 October 12th, 2009 07:41 AM
Adding a new Node to existing XML document Lupus81 XML 3 August 4th, 2009 04:57 PM
XML Node Appending Question webdevjeff XML 0 April 18th, 2006 06:13 AM
Appending one xml dataset to another badgolfer ASP.NET 1.0 and 1.1 Basics 0 October 18th, 2004 09:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.