Skip to main content
Skip table of contents

Creating a Merged Document

Introduction 

This document describes how you to "merge" two documents in a controlled way. For the resources associated with this sample, see the Bitbucket repository, here.

How to merge two documents using deltaxml:ignore-changes

In the examples on Ignoring Changes, the deltaxml:ignore-changes attribute is applied to individual elements or attributes in the data. However, it can also be applied to a subtree or indeed the entire document. When applied to a subtree, changes in that subtree are removed and therefore the only deltaxml:deltaV2 attribute will be located at the top of the subtree. If other parts of the file are not marked and processed then any deltaV2 markup remains, describing the changes to those parts of the tree.

If, for example, you place the attribute deltaxml:ignore-changes="B,A" on the root element, then you will get a merge of the two documents, with the B values of data (attributes, text etc.) being used in precedence to the A values when both are present.  The following 'mark' stylesheet will match the root element and add this attribute:

XML
<xsl:stylesheet version="2.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:deltaxml="http://www.deltaxml.com/ns/well-formed-delta-v1">
  
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@*, node()"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="/*">
    <xsl:copy>
      <xsl:attribute name="deltaxml:ignore-changes" select="'B,A'"/>
      <xsl:apply-templates select="@*, node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

When this is processed with the usual 'mark', 'apply', 'propagate' chain of filters the result will only have a deltaxml:deltaV2='A=B'attribute on the root element of the result tree and all other change markup will have been removed.  Subsequent use of the clean-house.xsl filter could then be used to remove this attribute and other delta attributes to give a result very close in style to the original inputs but with as much content from both inputs as is possible included in the result. This filter is available as part of the XML Compare release.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.