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

RE: Merge two xml files into one ?

Subject: RE: Merge two xml files into one ?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 11 Feb 2008 17:12:56 -0000
RE:  Merge two xml files into one ?
Try:

<xsl:template match="device">
  <xsl:copy-of select="param"/>
  <xsl:copy-of select="document('doc2.xml')/device/param"/>
</xsl:template>

If you want to make it symmetric you can read both inputs using the
document() function, or supply both as stylesheet parameters.

Michael Kay
http://www.saxonica.com/

 

> -----Original Message-----
> From: Kerry, Richard [mailto:richard.kerry@xxxxxxxxxxx] 
> Sent: 11 February 2008 17:08
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Merge two xml files into one ?
> 
>  
>  
> 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.
>  
> I've done this in the past by a program that reads both trees 
> and just adds the second after the last child of the first 
> and write out the result.
> This looks to me like something that ought to be possible to 
> do by some extremely simple bit of Xsl but I'm not sure what.
>  
> Appreciatively,
> Richard.
>  
>  
> 
> Richard Kerry
> Colledia Control Engineer
> Siemens IT Solutions and Services Ltd
> Room 457 Design Building, BBC Television Centre, Wood Lane, 
> London, W12 7RJ
> T: +44 (0)20 82259063 F: +44 (0)20 8576 8182 M: +44 (0)7921 244993
> Email: richard.kerry@xxxxxxxxxxx
> <blocked::mailto:richard.kerry@xxxxxxxxxxx>
> Website:  www.siemens.co.uk/it-solutions 
> <blocked::outbind://47/www.siemens.co.uk/it-solutions> 
> 
> This e-mail contains confidential information and is for the 
> exclusive use of the addressee/s.  If you are not the 
> addressee, then any distribution, copying or use of this 
> e-mail is prohibited. If received in error, please advise the 
> sender and delete it immediately.  We accept no liability for 
> any loss or damage suffered by any person arising from use of 
> this e-mail.
> 
> Siemens IT Solutions and Services Limited Registered No: 
> 1203466 England Registered Office: Faraday House, Sir William 
> Siemens Square, Frimley, Camberley, GU16 8QD

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.