|
Subject: Re: [xsl] combining multiple xml files From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 20 May 2003 18:10:35 -0400 |
I am wanting to combine multiple xml files looking as follows: ... and have the output look as such...any suggestions?
t:\ftemp>type rj1.xml
<class>
<id>001</id>
<name>beginning</name>
<section>
<id>100</id>
<name>Anderson</name>
<detail>some text</detail>
</section>
</class>t:\ftemp>type rj2.xml
<class>
<id>001</id>
<name>beginning</name>
<section>
<id>100</id>
<name>Anderson</name>
<detail>some more text</detail>
</section>
</class>t:\ftemp>type rj3.xml
<class>
<id>001</id>
<name>beginning</name>
<section>
<id>200</id>
<name>Anderson</name>
<detail>more text</detail>
</section>
</class>t:\ftemp>type rj4.xml
<class>
<id>002</id>
<name>advanced</name>
<section>
<id>100</id>
<name>Jones</name>
<detail>some final text</detail>
</section>
</class>t:\ftemp>type rj.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="classes" select="document('rj1.xml')/class |
document('rj2.xml')/class |
document('rj3.xml')/class |
document('rj4.xml')/class"/><xsl:template match="/">
<output>
<xsl:for-each select="$classes">
<xsl:if test="generate-id(.)=
generate-id($classes[id=current()/id and
name=current()/name])">
<class>
<id><xsl:value-of select="id"/></id>
<name><xsl:value-of select="name"/></name>
<xsl:variable name="classesbyidandname"
select="$classes[id=current()/id and
name=current()/name]"/>
<xsl:for-each select="$classesbyidandname">
<xsl:if test="generate-id(.)=
generate-id($classesbyidandname
[section/id=current()/section/id and
section/name=current()/section/name])">
<xsl:variable name="sections"
select="$classesbyidandname
[section/id=current()/section/id and
section/name=current()/section/name]
/section"/>
<xsl:for-each select="$sections">
<xsl:if test="generate-id(.)=
generate-id($sections[id=current()/id and
name=current()/name])">
<section>
<id><xsl:value-of select="id"/></id>
<name><xsl:value-of select="name"/></name>
<xsl:variable name="details"
select="$sections[id=current()/id and
name=current()/name]
/detail"/>
<xsl:for-each select="$details">
<xsl:if test="generate-id(.)=
generate-id($details[.=current()])">
<detail><xsl:value-of select="."/></detail>
</xsl:if>
</xsl:for-each>
</section>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</class>
</xsl:if>
</xsl:for-each>
</output>
</xsl:template>t:\ftemp>type rjout.xml
<?xml version="1.0" encoding="utf-8"?>
<output>
<class>
<id>001</id>
<name>beginning</name>
<section>
<id>100</id>
<name>Anderson</name>
<detail>some text</detail>
<detail>some more text</detail>
</section>
<section>
<id>200</id>
<name>Anderson</name>
<detail>more text</detail>
</section>
</class>
<class>
<id>002</id>
<name>advanced</name>
<section>
<id>100</id>
<name>Jones</name>
<detail>some final text</detail>
</section>
</class>
</output>-- 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 Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] combining multiple xml files, RJ P | Thread | [xsl] Splitting a relative link in , Wolfgang Schreurs |
| RE: [xsl] How to input a variable i, cknell | Date | RE: [xsl] Pass node to template, Michael Kay |
| Month |