Subject: merging a node from one XML to another
Posted By: pravind Post Date: 2/20/2006 4:22:52 AM
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

Reply By: mhkay Reply Date: 2/20/2006 10:11:16 AM
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
Reply By: pravind Reply Date: 2/20/2006 11:28:31 PM
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:
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



Reply By: mhkay Reply Date: 2/21/2006 4:04:43 AM
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

Go to topic 40348

Return to index page 364
Return to index page 363
Return to index page 362
Return to index page 361
Return to index page 360
Return to index page 359
Return to index page 358
Return to index page 357
Return to index page 356
Return to index page 355