On 11/02/2008, Kerry, Richard <richard(_dot_)kerry(_at_)siemens(_dot_)com>
wrote:
Can I use XSL to merge the contents of two xml files into one ?
I have :
File1.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE device SYSTEM "device.dtd">
<device name="Test">
<param name="CommsStatus" slot="2" />
<param name="DriverStatus" slot="3" />
<param name="LastDeviceError" slot="4" />
<param name="AlarmCount" slot="5" />
<param name="QuietMode" slot="6" />
</device>
File2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE device SYSTEM "device.dtd">
<device>
<param name="CommsStatus" slot="5" />
<param name="DriverStatus" slot="6" />
<param name="LastDeviceError" slot="7" />
<param name="AlarmCount" slot="8" />
<param name="QuietMode" slot="9" />
</device>
I want:
File3.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE device
SYSTEM "device.dtd">
<device name="Test">
<param name="CommsStatus" slot="2" />
<param name="DriverStatus" slot="3" />
<param name="LastDeviceError" slot="4" />
<param name="AlarmCount" slot="5" />
<param name="QuietMode" slot="6" />
<param name="CommsStatus" slot="5" />
<param name="DriverStatus" slot="6" />
<param name="LastDeviceError" slot="7" />
<param name="AlarmCount" slot="8" />
<param name="QuietMode" slot="9" />
</device>
Note that I don't care about the order of slot numbers, the contents of
the second file just gets added at the end.
Also that I will assume the same dtd and outermost element for both
files.
Use the indentity template (see the other post a few minutes ago) with:
<xsl:template match="device">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:copy-of select="document('file:/c:/path/to/file2.xml')/device/param"/>
</xsl:copy>
</xsl:template>
This assumes you are processing file1.xml and want to include
file2.xml - you'd probably want to separate out the path to a
parameter.
cheers
--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--