Merge Formatting Elements with Rule Processing Sample
Merge allows users to mark elements as formatting elements. For these elements the merge operation focuses on textual changes rather than structural changes. See Merge — Formatting Elements Sample and Merge — Formatting Element Representations for background.
Merge also provides rule processing to automatically resolve simple changes. This sample demonstrates the behaviour of formatting elements when rule processing is enabled. See Merge — Rule Based Processing for more detail on rule processing.
Applying Rules to Formatting Elements
When rule processing is enabled, Merge accepts simple adds, deletes, and modifications to attributes, elements, and their contents. For formatting elements specifically:
-
Addition of formatting element tags — accepted and kept in the result.
-
Deletion of formatting element tags — accepted and removed from the result.
-
Addition introducing an overlap — not a simple change; not resolved during rule processing.
The default behaviour can be adjusted using RuleConfiguration methods:
-
setDisplaySimpleAdds(boolean)— control whether simple additions are accepted. -
setDisplaySimpleDeletes(boolean)— control whether simple deletions are accepted. -
setDisplayChangesInvolving(Set)— show formatting changes involving a specific version. -
setDisplayFormatChangesIn(String)— show formatting changes inside elements matching an XPath.
Example
Three versions of a simple document, with "A" as the common ancestor. Version "B" adds <bold> in the first paragraph; version "C" removes <italic> in the second paragraph.
A (ancestor)
<document>
<para>Example of formatting addition around the word.</para>
<para>Example of formatting deletion around the <italic>word</italic>.</para>
</document>
B
<document>
<para>Example of formatting addition around the <bold>word</bold>.</para>
<para>Example of formatting deletion around the <italic>word</italic>.</para>
</document>
C
<document>
<para>Example of formatting addition around the <bold>word</bold>.</para>
<para>Example of formatting deletion around the word.</para>
</document>
Results
DeltaV2.1 result — rule processing disabled:
<document deltaxml:version-order="A, B, C" deltaxml:version="2.1" deltaxml:deltaV2="A!=B!=C">
<para deltaxml:deltaV2="A!=B=C">Example of formatting addition around the
<bold deltaxml:deltaTag="B,C" deltaxml:deltaV2="A!=B=C">word</bold>.</para>
<para deltaxml:deltaV2="A=B!=C">Example of formatting deletion around the
<italic deltaxml:deltaTag="A,B" deltaxml:deltaV2="A=B!=C">word</italic>.</para>
</document>
DeltaV2.1 result — rule processing enabled (added <bold> accepted, deleted <italic> removed):
<document deltaxml:version-order="A, B, C" deltaxml:version="2.1" deltaxml:deltaV2="A=B=C">
<para>Example of formatting addition around the <bold>word</bold>.</para>
<para>Example of formatting deletion around the word.</para>
</document>
DeltaV2.1 result — rule processing enabled, displayChangesInvolving set to "B" (addition of <bold> involving B is kept; deletion of <italic> involving C is resolved):
<document deltaxml:version-order="A, B, C" deltaxml:version="2.1" deltaxml:deltaV2="A!=B=C">
<para deltaxml:deltaV2="A!=B=C">Example of formatting addition around the
<bold deltaxml:deltaTag="B,C" deltaxml:deltaV2="A!=B=C">word</bold>.</para>
<para deltaxml:deltaV2="A=B=C">Example of formatting deletion around the word.</para>
</document>
DeltaV2.1 result — rule processing enabled, displayFormatChangesIn set to XPath //para (formatting changes inside all para elements are displayed):
<document deltaxml:version-order="A, B, C" deltaxml:version="2.1" deltaxml:deltaV2="A!=B!=C">
<para deltaxml:deltaV2="A!=B=C">Example of formatting addition around the
<bold deltaxml:deltaTag="B,C" deltaxml:deltaV2="A!=B=C">word</bold>.</para>
<para deltaxml:deltaV2="A=B!=C">Example of formatting deletion around the
<italic deltaxml:deltaTag="A,B" deltaxml:deltaV2="A=B!=C">word</italic>.</para>
</document>
Implementation
The sample is implemented in the main method of FormattingElementsWithRuleProcessing.java.
Running the Sample
Full source and instructions are available on Bitbucket.