[xsl] Recursively Merging 2 XML files with XSLT

Subject: [xsl] Recursively Merging 2 XML files with XSLT
From: "Daniel MacDonald" <danmec1@xxxxxxxxx>
Date: Thu, 23 Nov 2006 12:05:53 +0000
Hi there, I'm having a problem with merging a couple of XML files.
I've found a few examples of merging on-line but none that really

Basically I have an XML file which is written out by my Java program
that looks something like this:

  <data val="xx">
     <data val="yy">
        <data val="ss"></data>
  <data val="gg"></data>

The number of children and siblings can change by the way.

Therefore in the XSLT document I'm displaying the data recursively, i.e.

<tr><td><xsl:value-of select="@val"/></td></tr>
<xsl:for-each select="*">
  <xsl:call-template name="itself"></xsl:call-template>

This all works fine, but I now need to do a side by side comparison with another XML document that has exactly the same structure, but could have different values. I'm not sure how to do this, perhaps using the same recursive code and using a sort of pointer to where you are in the 2nd XML file (see below), but I've no idea how to go about this?

<tr><td><xsl:value-of select="@val"/></td>
      <td><xsl:value-of select="<2nd documents @val>"/></td>
<xsl:for-each select="*">
  <xsl:call-template name="itself"></xsl:call-template>


xx    xy
yy    yy
ss   ss
gg   hh

Does anybody have any suggestions or help on how to achieve this?


Current Thread