Its now time to compare this XQuery with a modified version, these are the changes I made:
- Swapped the order of the local:summary-full and local:summary-short function declarations
- In local:summary-full(): Added ‘company’ to $emps/deptno to give $emps/company/deptno
- In local:summary-full(): Added a ‘serial’ attribute to the ‘dept’ element constructor
- In local:summary-full(): Removed the ‘full’ child element from the ‘dept’ element constructor
- In local:summary-short(): Changed ‘$emps[deptno = $d]’ to be ‘$emps[deptno ne $d]’
And here is the result of using DeltaXML Core to compare this modified version with the original – using orderless comparison with keys:
As we can see above, the changes have been marked clearly and there is no issue with the different order of the function declarations (the result shows the order of the original by default). It’s now time to look at the output from DeltaXML Core from the same input, but this time when keyed comparison is not used:
The above result shows that, when using ordered comparison, correct changes are not picked up and that incorrect changes are reported, simply because the correct functions have not been aligned and therefore the wrong functions have been compared with each other.
Conclusion
By creating a filter to add wrapper elements with unique keys to XQuery function declarations, we were able to exploit DeltaXML Core’s orderless comparison and ignore changes in the order of function declarations within the XQuery prolog – the example comparison showed that this allowed an accurate result where other comparators would fail. It would be relatively straightforward to extend the ‘wrap-spans’ template and ‘key-xquery.xsl’ filter to handle other orderless language constructs such as variable declarations.
Future Enhancements
One feature that I think could be useful would be a ‘ghost’ image showing a faint rendering of the place where the code block occurred in the other version (see below), this could probably be done best with an extra input/output filter to use a ‘placeholder’ element as a reference – hopefully I will get the chance to try this out in a further blog post.