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

RE: merging xml files


merge xml xslt
I could accomplish my task following the example on
http://www.xml.com/pub/a/2003/11/26/q-and-a.html
However, the problem I identify is that my xsl is too tied up with the xmls.


I find that Michael's flow is better as it checks for 'not' condition
instead of constructing everything in the xslt.
The problem I am with now is that this step is not very clear on how to
implement the 'not' part that is if it is required to add 'X' from 'B'

??
If we hit an E that doesn't contain an X, we add the X from B:

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

Can you explain Michael? - what should I replace 'E' with?

Thanks again.

Pank


-----Original Message-----
From: Michael Kay [mailto:michael.h.kay@n...]
Sent: Wednesday, September 01, 2004 7:17 PM
To: 'Pankaj Rathi'; xml-dev@l...
Subject: RE:  merging xml files


> 
> Looking at the interest and in reply to Michael, I am expressing my
> requirements again, in case, someone can give a refined solution.
> 
> The task is to merge two xml files. Both the 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(which is not root).
> 
> If File A contains node X (the location is known):
> XSLT should still get it from file B and replace the one 
> existing in File A.

First let my try to rephrase your requirements using standard terminology,
to check that I have understood them correctly.

The task is to merge two XML documents. The name of the document element of
both documents is the same in both cases [but we don't use this fact].

Document A contains zero or one elements with the name X.
Document B contains exactly one element with the name X.

If document A does not contain an element named X:
the stylesheet should deep-copy the X element from document B and insert it
in Document A at a defined location.

If document A does contain an element named X:
the stylesheet should deep-copy the X element from document B and insert it
in Document A replacing the original X element.

You haven't said what "the defined location" is, but let's suppose that it's
an E element which either does or does not contain X as a child.

So, you start with an identity transform on A:

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

If we hit an X, we replace it:

<xsl:template match="X">
 <xsl:copy-of select="document('B.xml')//X"/>
</xsl:template>

If we hit an E that doesn't contain an X, we add the X from B:

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

Michael Kay


_____________________________________________________________________
This e-mail has been scanned for viruses by MCI's Internet Managed Scanning
Services - powered by MessageLabs. For further information visit
http://www.mci.com

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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.