xsl-list
[Top] [All Lists]

Re: [xsl] Problems merging two xml documents

2009-05-04 13:07:38
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/

--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>