Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] Merging two XML files

From: "Sachidanandam E K" <sachidanandam.kumaraswamy@-------------->
To:
Date: 7/1/2002 2:45:00 AM
http://www.jenitennison.com/xslt/index.html
Look here..Jeni had done it already..!!

Cheers!!
Sachi


Sachidanandam.E.K
Member Techinical Staff

HCLT KT-ODC
sachidanandam.kumaraswamy@xxxxxxxxxxxxxx
<mailto:sachidanandam.kumaraswamy@xxxxxxxxxxxxxx>


-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Kalyan Kumar
Mudumbai
Sent: Monday, July 01, 2002 2:34 PM
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Merging two XML files


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


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


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent