|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Merge - a.xml + b.xml = c.xml
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
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








