Subject: Re: [xsl] merging multiple xml files From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Wed, 04 Jun 2003 16:01:48 -0400 |
I have multiple xml files that I wish to merge. An example of the files is below. Note that a file may contain thousands of <detail> nodes.
I have been using a master xml file to try and merge but with no success in keeping the clients together.
Also, due to the size of the files, is using xsl:copy and xsl:copy-of the best way to approach this.
T:\ftemp>type peterson.xml <masterfile> <doc filename="file1.xml"/> <doc filename="file2.xml"/> <doc filename="file3.xml"/> </masterfile>
T:\ftemp>type file1.xml <client> <name>A</name> <subclient> <name>a</name> <detail>....</detail> <detail>....</detail> </subclient> </client>
T:\ftemp>type file2.xml <client> <name>A</name> <subclient> <name>b</name> <detail>....</detail> <detail>....</detail> </subclient> </client>
T:\ftemp>type file3.xml <client> <name>B</name> <subclient> <name>c</name> <detail>....</detail> <detail>....</detail> </subclient> </client>
T:\ftemp>type peterson.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="masterfile"> <merged> <xsl:variable name="clients" select="document(doc/@filename)/client"/>
<xsl:for-each select="$clients"> <xsl:if test="generate-id(.)= generate-id($clients[name=current()/name])"> <client> <xsl:copy-of select="name"/> <xsl:copy-of select="$clients[name=current()/name]/subclient"/> </client> </xsl:if> </xsl:for-each> </merged> </xsl:template>
T:\ftemp>type peterson.out <?xml version="1.0" encoding="utf-8"?> <merged> <client> <name>A</name> <subclient>
</subclient> <subclient>
</subclient> </client> <client> <name>B</name> <subclient>
</subclient> </client> </merged>
-- Upcoming hands-on courses: (registration still open!) - (XSLT/XPath and/or XSL-FO) North America: June 16-20, 2003
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) ISBN 0-13-065196-6 Definitive XSLT and XPath ISBN 0-13-140374-5 Definitive XSL-FO ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath ISBN 1-894049-11-X Practical Formatting Using XSL-FO Member of the XML Guild of Practitioners: http://XMLGuild.info Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] merging multiple xml files, RPeterson | Thread | Re: [xsl] merging multiple xml file, Rick Taylor |
RE: [xsl] importing/including a sty, Robert Koberg | Date | Re: [xsl] importing/including a sty, florian |
Month |