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

RE: merge/join two xml files.

Subject: RE: merge/join two xml files.
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 27 Nov 2006 21:55:00 -0000
join two xml files
It depends on many details that you haven't supplied, but let's assume 

(1) apart from the handling of X, the rest of the transformation is copying
A.xml unchanged.

(2) the element that might or might not contain an X child is called P, and
this is the only P element in the document, and the X element from B.xml is
to be added as the last child of P.

Then with A as the principal input document do:

<xsl:template match="*">
  <xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="P[not(X)]">
  <xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates/>
  <xsl:copy-of select="document('B.xml')//X"/>
  </xsl:copy>  
</xsl:template>

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

> -----Original Message-----
> From: chun ji [mailto:cji_work@xxxxxxxxx] 
> Sent: 27 November 2006 20:56
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  merge/join two xml files. 
> 
> (Sorry if this quiestion have been asked before, cause I just 
> joined this group 5 minutes ago. ) 
> 
> I have two files, A.xml and B.xml. Both files have the same root. 
> File A might or might not have node X(and its sub elements).
> File B will always have node X(and its sub elements).
> 
> If File A does not contain node X, XSLT should get it from 
> file B and insert it in File A under the defined location.
>  
> If File A contains node X (the location is known), XSLT 
> should still get it from file B and replace the one existed in File A.
> 
> Does someone know how to make it happen by XSLT ? 
> 
> 
> Thanks a lot !
> 
> 
> Chun 
> 
> 
> 
> 
>  
> ______________________________________________________________
> ______________________
> Cheap talk?
> Check out Yahoo! Messenger's low PC-to-Phone call rates.
> http://voice.yahoo.com

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

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-2007 All Rights Reserved.