Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] Re: Problems merging two xml documents

From: sp <spamthis@----------.--->
To: xsl-list@-----.------------.---
Date: 5/19/2009 2:52:00 PM
Ahh I understand, very enlightening thank you soo much!

all the best

Date: Mon, 04 May 2009 19:07:03 +0200
To:  xsl-list@l...
From: Martin Honnen <Martin.Honnen@g...>
Subject: Re: [xsl] Problems merging two xml documents
Message-ID: <49FF20B7.3070809@g...>

sp wrote:

> final doc, which is just a new version of doc1:
>
>
> <doc1>
>
> <a>
>  <a1></a1>
>  <a2></a2>
>  <!-- etc -->
> </a>
>
> <b>
>  <b1></b1>
>  <b2></b2>
>  <!--etc -->
> </b>
>
> <c>
>  <c1>more recent stuff</c1>
>  <c2>more recent stuff</c2>
>  <!--etc -->
> </c>
>
> <d> new element not in doc1 </d>
>
> </doc1>

Here is a sample XSLT 2.0 stylesheet that does the job with Saxon 9 and
the XML input samples you provided:

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0">

  <xsl:output indent="yes"/>

  <xsl:param name="url2" select="'test2009050404.xml'"/>
  <xsl:variable name="d2" select="document($url2)"/>

  <xsl:template match="/*">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <xsl:apply-templates select="*"/>
      <xsl:copy-of select="$d2/*/*[not(some $c in current()/* satisfies
(node-name(.) eq node-name($c)))]"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="/*/*">
    <xsl:copy>
      <xsl:copy-of select="*[not(some $c in $d2/*/*[node-name(.) eq
node-name(current())]/* satisfies (node-name(.) eq node-name($c)))]"/>
      <xsl:copy-of select="$d2/*/*[node-name(.) eq
node-name(current())]/*"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

--

       Martin Honnen
       http://msmvps.com/blogs/martin_honnen/

On Mon, May 4, 2009 at 9:31 AM, sp <spamthis@d...> wrote:
> HI,
>
> I'm trying to merge and copy two xml documents, into a new xml
> document and in a nutshell no matter what xsl I write I have yet to
> been able to get it to merge as I desire.
>
> I don't just want the content of the elements, I want to make a copy
> of each element making a new xml document. I've been utilizing the xsl
> copy-of and the document() to try and do this, with merge and copy
> examples as my guide.
>
> After a day and a half of trying, I've gotten close, but still can't
> get any one example to do what I need.  I don't know what of my many
> efforts to provide as an example, so I thought I should just
> illustrate below what I want and see if anyone can offer help.
>
> thanks in advance for any suggestions or examples.
>
> This document is merged with doc2, to form a new version of doc1.  Any
> common elements from doc2 replace doc1s elements of the same name, any
> new elements from doc2 are added
>
> <doc1>
>
> <a>
>  <a1></a1>
>  <a2></a2>
>  <!-- etc -->
> </a>
>
> <b>
>  <b1></b1>
>  <b2></b2>
>  <!--etc -->
> </b>
>
> <c>
>  <c1></c1>
>  <c2></c2>
>  <!--etc -->
> </c>
>
> </doc1>
>
> All except root element should be merged into doc1,  if element
> already exists it replaces the ones in doc1
>
> <doc2>
>
> <c>
>  <c1>more recent stuff</c1>
>  <c2>more recent stuff</c2>
>  <!--etc -->
> </c>
>
> <d> new element not in doc1 </d>
>
> </doc2>
>
>
> final doc, which is just a new version of doc1:
>
>
> <doc1>
>
> <a>
>  <a1></a1>
>  <a2></a2>
>  <!-- etc -->
> </a>
>
> <b>
>  <b1></b1>
>  <b2></b2>
>  <!--etc -->
> </b>
>
> <c>
>  <c1>more recent stuff</c1>
>  <c2>more recent stuff</c2>
>  <!--etc -->
> </c>
>
> <d> new element not in doc1 </d>
>
> </doc1>
>
>
> thank you
>

--~------------------------------------------------------------------
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@l...>
--~--



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent