[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Merging two XML files

Subject: Merging two XML files
From: "Kalyan Kumar Mudumbai" <kalyan_tech@xxxxxxxxxxxxxx>
Date: 1 Jul 2002 09:03:35 -0000
merge two xml
Hi All, I'm new to using XSL. I have a small problem while merging two xml files. I have two xml files and one xsl file which merges them as shown below. And the result is also shown below
--------------
Input.xml
--------------
<?xml version="1.0" encoding="UTF-8"?>
<Person>
<Name>
<LastName/>
<FirstName/>
</Name>
</Person>
-------------------
Doc.xml
-----------------
<?xml version="1.0" encoding="UTF-8"?>
<Person>
<Name>
<MiddleName/>
</Name>
</Person>
-------------------
Merge.xsl
-------------------
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />


<!--source of data; default can be overridden on command line-->
   <xsl:param name="source" select="'./Doc.xml'" />

<!-- Copy XSL elements and their attributes -->
   <xsl:template match="*">
      <xsl:copy>
         <xsl:for-each select="@*">
            <xsl:copy>
               <xsl:value-of select="." />
            </xsl:copy>
         </xsl:for-each>

         <xsl:apply-templates select="node()" />
      </xsl:copy>
   </xsl:template>

<xsl:template match="Name">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:copy>
<xsl:value-of select="." />
</xsl:copy>
</xsl:for-each>
<xsl:apply-templates select="*" />
<xsl:apply-templates select="document($source)/Person/Name/MiddleName" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
-----------------------------------
Result.xml
-------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<Person>
<Name>
<LastName/>
<FirstName/>
<MiddleName/>
</Name>
</Person>
----------------------------------


So, from the two input files it is obvious that I wanted to merge the leaf nodes of <Name>. I was able to do that using the above Merge.xsl file, but there is a problem with that. In one of the templates I had to hardcode that select="Name". But what I wanted to do is, without any hardcoding, I wanted to get the local-name() of the current node, for example "Name", lookup in the Doc.xml file, if there is any node with it's name as "Name" and then merge. There shouldn't be any sort of hardcoding. Can someone help me out in doing that.

              Thanks,
Regards,
Kalyan

_________________________________________________________
There is always a better job for you at Monsterindia.com.
Go now http://monsterindia.com/rediffin/


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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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