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 February 20th, 2006, 05:22 AM
Authorized User
 
Join Date: Feb 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default merging a node from one XML to another

Hi,
I want to merge a node from one xml document to another as per solution given by Michael as follows

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


but implementing this I am able to copy the complete file but not specific xml Node.

<xsl:copy-of select="document('file2.xml')/*"/>
after this statement I can able to add a complete file
 but when I use <xsl:copy-of select="document('file2.xml')/services/service"/>
I am not able to add services/service node in to file1.xml

 
Old February 20th, 2006, 11:11 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You need to show what your input files were, what result you obtained, and what result you wanted.

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

Input files are

File 1:
<?xml version="1.0" encoding="iso-8859-1" ?><confirmationDocument xmlns="http://schema.umbrella.ch/UmbrellaB2B/uB2B_Confirmation" xmlns:xsi="http://www.w3.org/2001/XMLSchema" origin="Galileo" type="Unticketed" id="1" creationDate="2006-02-16" modifyDate="2006-02-16" modifyTime="08:23:00">
<participants>
<participant participantNr="1">
<name>Mueller</name>
<firstname>Markus</firstname>
</participant>
</participants>
<services>
<service xmlns="" xsi:type="SrvcFlight" id="0">
<flightno>1233</flightno>
<flightCode>A34</flightCode>
</service>
</services>
</confirmationDocument>

File 2:
<?xml version="1.0" encoding="iso-8859-1" ?><confirmationDocument xmlns="http://schema.umbrella.ch/UmbrellaB2B/uB2B_Confirmation" xmlns:xsi="http://www.w3.org/2001/XMLSchema" origin="Galileo" type="Unticketed" id="1" creationDate="2006-02-16" modifyDate="2006-02-16" modifyTime="08:23:00">
<participants>
<participant participantNr="1">
<name>Mueller</name>
<firstname>Markus</firstname>
</participant>
</participants>
<services>
<service xmlns="" xsi:type="SrvcCar" id="1">
<carno>1233</carno>
<carProvider>AVIS</carProvider>
</service>
</services>
</confirmationDocument>

Expected Output:
<?xml version="1.0" encoding="iso-8859-1" ?><confirmationDocument xmlns="http://schema.umbrella.ch/UmbrellaB2B/uB2B_Confirmation" xmlns:xsi="http://www.w3.org/2001/XMLSchema" origin="Galileo" type="Unticketed" id="1" creationDate="2006-02-16" modifyDate="2006-02-16" modifyTime="08:23:00">
<participants>
<participant participantNr="1">
<name>Mueller</name>
<firstname>Markus</firstname>
</participant>
</participants>
<services>
<service xmlns="" xsi:type="SrvcFlight" id="0">
<flightno>1233</flightno>
<flightCode>A34</flightCode>
</service>
<service xmlns="" xsi:type="SrvcCar" id="1">
<carno>1233</carno>
<carProvider>AVIS</carProvider>
</service>
</services>
</confirmationDocument>


There may be any no of service in both the files.



Quote:
quote:Originally posted by mhkay
 You need to show what your input files were, what result you obtained, and what result you wanted.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 21st, 2006, 05:04 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Looks something like this:

<xsl:stylesheet... xmlns:c="http://schema.umbrella.ch/UmbrellaB2B/uB2B_Confirmation">

<xsl:template match="c:confirmationDocument">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:copy-of select="c:participants"/>
    <services>
     <xsl:copy-of select="c:services/service"/>
     <xsl:copy-of select="document('2.xml')/c:confirmationDocument/c:services/service"/>
    </services>
   </xsl:copy>
</xsl:template>

I expect it was the rather weird use of namespaces that was throwing you. Which shows how important it is to give a complete example of the problem, not just the bits you think are relevant. Very often the problem is in the bits you didn't think mattered.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
merging 2 xml with xslt gbordel XSLT 7 April 24th, 2008 05:27 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
merging xml using xslt sormel XSLT 1 July 9th, 2007 06:07 PM
Merging XML Help Please sam666 XML 7 March 8th, 2006 02:50 AM
merging 2 xml documents espider4u XSLT 0 August 31st, 2004 11:48 AM





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