title: how to compare and merge two xml using xslt
body: <p>I want to compare two xmls and then merge them. For example:</p>
  
  <p>myFile1.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;catalog&gt;
  &lt;data&gt;
      &lt;title&gt;Title1&lt;/title&gt;
      &lt;description&gt;Description1&lt;/description&gt;
      &lt;myid&gt;1&lt;/myid&gt;
  &lt;/data&gt;
  &lt;data&gt;
      &lt;title&gt;Title2&lt;/title&gt;
      &lt;description&gt;Description2&lt;/description&gt;
      &lt;myid&gt;2&lt;/myid&gt;
  &lt;/data&gt;
  &lt;/catalog&gt;
  </code></pre>
  
  <p>myFile2.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;catalog&gt;
  &lt;data&gt;
      &lt;title&gt;Title1&lt;/title&gt;
      &lt;description&gt;Description1&lt;/description&gt;
      &lt;author&gt;Author1&lt;/author&gt;
      &lt;date&gt;12/34/5678&lt;/date&gt;
      &lt;myid&gt;1&lt;/myid&gt;
  &lt;/data&gt;
  &lt;data&gt;
      &lt;author&gt;Author2&lt;/author&gt;
      &lt;date&gt;87/65/4321&lt;/date&gt;
      &lt;myid&gt;2&lt;/myid&gt;
  &lt;/data&gt;
  &lt;/catalog&gt;
  </code></pre>
  
  <p>Desired Output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;catalog&gt;
  &lt;data&gt;
      &lt;title&gt;Title1&lt;/title&gt;
      &lt;description&gt;Description1&lt;/description&gt;
      &lt;myid&gt;1&lt;/myid&gt;
      &lt;author&gt;Author1&lt;/author&gt;
      &lt;date&gt;12/34/5678&lt;/date&gt;
  &lt;/data&gt;
  &lt;data&gt;
      &lt;title&gt;Title2&lt;/title&gt;
      &lt;description&gt;Description2&lt;/description&gt;
      &lt;myid&gt;2&lt;/myid&gt;
      &lt;author&gt;Author2&lt;/author&gt;
      &lt;date&gt;87/65/4321&lt;/date&gt;
  &lt;/data&gt;
  &lt;/catalog&gt;
  </code></pre>
  
  <p>I have a code but, it doesnot perform as per the required output.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/&gt;
  &lt;xsl:variable name="compare" select="'myFile1.xml'"/&gt;
  &lt;xsl:variable name="with" select="'myFile2.xml'"/&gt;
  &lt;xsl:template match="@*|node()"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:apply-templates select="@*|node()"/&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="*"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:apply-templates select="@*|node()"/&gt;
          &lt;xsl:variable name="info1" select="document($compare)/catalog/data[myid=current()/myid]/."/&gt;
          &lt;xsl:variable name="info2" select="document($with)/catalog/data[myid=current()/myid]/."/&gt;
          &lt;xsl:for-each select="$info1/*"&gt;
              &lt;xsl:variable name="check1" select="name(current())"/&gt;
              &lt;!--xsl:text&gt;Current node1 : &lt;/xsl:text&gt;&lt;xsl:value-of select="$check1"/--&gt;
              &lt;xsl:for-each select="$info2/*"&gt;
                  &lt;xsl:variable name="check2" select="name(current())"/&gt;
                  &lt;!--xsl:text&gt;Current node2 : &lt;/xsl:text&gt;&lt;xsl:value-of select="$check2"/--&gt;
                  &lt;xsl:if test="$check1!=$check2"&gt;
                      &lt;xsl:copy-of select="."/&gt;
                  &lt;/xsl:if&gt;
              &lt;/xsl:for-each&gt;
          &lt;/xsl:for-each&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:transform&gt;
  </code></pre>
  
  <p>Please Help!</p>