Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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 February 18th, 2006, 03:12 AM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default append a xml node from one file to another

Hi,
I have problem to append a node from one XMl to another XML
for Eg:
File1.xml
<?xml version="1.0"?>
<services>
<service xmlns="" xsi:type="SrvcFlight" id="1">
<flight>
<Flno>123</Flno>
<Flname>ABCD</Flname>
</flight>
<customer>
<name>Mr. xyz</name>
<age>45</age>
</customer>
</serivce>
<service xmlns="" xsi:type="SrvcFlight" id="2">
<flight>
<Flno>1234</Flno>
<Flname>ABCDX</Flname>
</flight>
<customer>
<name>Mr. lmn</name>
<age>45</age>
</customer>
</serivce>
</services>
<services>

File2.xml
<?xml version="1.0"?>
<services>
<service xmlns="" xsi:type="SrvcCar" id="1">
<car>
<carno>1234</carno>
<provider>ABCDX</provider>
<type>Ford</type>
</car>
<customer>
<name>Mr. lmn</name>
<age>45</age>
</customer>
</serivce>
</services>
<services>


As per this Example I want to Append the service Car node from File2.xml To child of services node from File1.xml

is there any solution for this.



 
Old February 18th, 2006, 06:08 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sure.

<xsl:template match="/">
<services>
  <xsl:copy-of select="/services/service"/>
  <xsl:copy-of select="document('file2.xml')/services/service"/>
</services>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 20th, 2006, 12:25 AM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Thanks for Reply It works using XSL

But in more on that I want to do it using PHP,and DOMXML or using XPATH.

Is it Possible ?

Regards,
Pravin.

 
Old February 20th, 2006, 01:32 AM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 Hi,
Thanks for Reply It works using XSL

I want TO process these two xml file using PHP and DOMXML,
I have installed XSLT libs for PHP .

Can You Please guide me How I use this XSL using PHP.


Regards,
Pravin.


Quote:
quote:Originally posted by mhkay
 Sure.

<xsl:template match="/">
<services>
  <xsl:copy-of select="/services/service"/>
  <xsl:copy-of select="document('file2.xml')/services/service"/>
</services>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 20th, 2006, 10:51 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you want a solution in PHP, then asking the question on an XSLT forum is probably not your best strategy.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 22nd, 2009, 09:15 AM
Registered User
 
Join Date: Aug 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Created Example

I have created working example for this, check the link

http://dotutorial.com/tutorial-tut10...using-XSL.aspx




Similar Threads
Thread Thread Starter Forum Replies Last Post
append/insert data to xml file andhiez XML 5 April 18th, 2008 11:13 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
append in xml file rapraj XML 3 October 11th, 2007 02:58 AM
Append Information to a XML file YoungLuke C# 2 July 26th, 2007 02:15 PM
append data to xml andhiez General .NET 0 June 14th, 2005 04:15 AM





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