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

Merge - a.xml + b.xml = c.xml

Subject: Merge - a.xml + b.xml = c.xml
From: "Exide Arabellan" <exide@xxxxxxxxxxx>
Date: Sat, 17 Aug 2002 05:50:04 +0000
jordon zander
To start it off, here are the files being used:

social1.xml
----------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE social SYSTEM "C:\Documents and Settings\Exide\Desktop\social1.dtd">
<social>
<friend name="Jordon">
<city>Aloha</city>
<job>Circuit City</job>
</friend>
</social>


social2.xml
----------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE social SYSTEM "C:\Documents and Settings\Exide\Desktop\social2.dtd">
<social>
<friend name="Jordon" lastname="Zander">
<url>www.jz.com</url>
<age>19</age>
</friend>
</social>


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


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

<xsl:template match="/">
  <social>
  <xsl:for-each select="social/friend">

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

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

<!-- copy the children of the matching friend node from the merge file -->
<xsl:copy-of select="$social2/social/friend[@name=$name]/child::*" />
</friend>
</xsl:for-each>
</social>
</xsl:template>
</xsl:stylesheet>


---
It works great for merging Elements, but i lose all Attributes to the 'friend' node. Here is the output:
---


output.xml
---------
<?xml version="1.0" encoding="UTF-16"?>
<social>
	<friend>
		<city>Aloha</city>
		<job>Circuit City</job>
		<url>www.jz.com</url>
		<age>19</age>
	</friend>
</social>

---
This is the output im striving for:
---
output.xml
---------
<?xml version="1.0" encoding="UTF-16"?>
<social>
	<friend name="Jordon" lastname="Zander">
		<city>Aloha</city>
		<job>Circuit City</job>
		<url>www.jz.com</url>
		<age>19</age>
	</friend>
</social>

---
Im quite new to XML but learning as i go along. Take a snippet of code from here and there, alter them into somethin that works for me. Learning what each line does as i go along. So my terminology may be bad =)
---


"I only do what my rice crispies tell me to"
Exide Arabellan


_________________________________________________________________ Chat with friends online, try MSN Messenger: http://messenger.msn.com


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.