[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: Arulraj <p_arulraj@xxxxxxxxx>
Date: Tue, 13 Jan 2004 00:57:24 -0800 (PST)
merge 2 xml files
Hi,
  
I want to merge two xml files, I am using document()in
xsl file for accessing one file and another file given
in command prompt for the parser. 

first xml file given below
employeeNames.xml
<?xml version="1.0" encoding="UTF-8"?>
<employees>
	<employee id="1">
		<lastname>Smith</lastname>
		<firstname>Marsha</firstname>
	</employee>
	<employee id="2">
		<lastname>Arul</lastname>
		<firstname>Raj</firstname>
	</employee>
	<employee id="3">
		<lastname>Jaya</lastname>
		<firstname>Raj</firstname>
	</employee>
</employees>

second xml file
employeeAddresses.xml

<?xml version="1.0" encoding="UTF-8"?>
<employees>
	<employee id="1" pincode="4">
		<address>115 Marshal Rd., 
      Greenville, MN 39281</address>
	</employee>
	<employee id="2" pincode="34">
		<address>chennai,India</address>
	</employee>
	<employee id="3" pincode="47">
		<address>Chennai</address>
	</employee>
</employees>

I am merging this XML file using XSLT
given below

<?xml version="1.0"?> 
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>

<!-- load the merge file -->
<xsl:variable name="emps"
select="document('employeeAddresses.xml')"/>

<xsl:template match="/">

   <employees>
   <xsl:for-each select="employees/employee">

   <!-- cache the employee's ID -->
   <xsl:variable name="id">
      <xsl:value-of select="@id"/></xsl:variable>

      <!-- copy the child nodes -->
      <employee>
      <xsl:copy-of select="child::*"/>

         <!-- copy the children of the matching
employee node 
         from the merge file -->
         <xsl:copy-of
select="$emps/employees/employee[@id=$id]/child::*" />
      </employee>
   </xsl:for-each>
   </employees>
</xsl:template>
</xsl:stylesheet>

Expected Output is:

<employees>
<employee pincode="4">
<lastname>Smith</lastname>
<firstname>Marsha</firstname>
<address>115 Marshal Rd., 
      Greenville, MN 39281</address>
</employee>
<employee pincode="34">
<lastname>Arul</lastname>
<firstname>Raj</firstname>
<address>chennai,India</address>
</employee>
<employee pincode="47">
<lastname>Jaya</lastname>
<firstname>Raj</firstname>
<address>Chennai</address>
</employee>
</employees>

By using above XSL I want get pincode attribute in
output file.
How to check that attribute exists in <employee> and
insert pincode attribute in produced output?

Please reply if you know,
Thanks in advance
Arul

__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus

 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.