[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

How Do I Generate A Set-Difference With Context - Part

Subject: How Do I Generate A Set-Difference With Context - Part A
From: "Aron Bock" <aronbock@xxxxxxxxxxx>
Date: Sat, 05 Mar 2005 09:25:07 +0000
set difference
Hello, I'm coming up against the edges of my journeyman usage of XSLT, and concurrent with my huddling down with some books I'm hoping to get pointers on the following.

I have 2 XML documents with the same schema, and I want to determine the set difference (not symmetric set difference) between them. True, this has had much written about it, but all the solutions I've seen simply show a collection of "differenced" nodes, in a format that bears little resemblence to the source document. Thus my twist is, I'd like to generate a set difference, and retain enough context so I end up with a document [tree] similar to the source--just pruned of unchanged nodes.

The "enough context" bears elaboration, but for now lets say I'd be happy if the end result preserves tree branches that lead from the changed node, all the way to the root. Each branch would imply at minimum (and show) a changed leaf and its attributes, all the way through the root and its attributes. In future I hope to be able to dynamically affect the meaning of "enough context", but that for later.

Now some sample data (adapted from Sal Mangano's "XSLT Cookbook"):

doc1.xml
======
<doc>
   <chapter n="1">
       <section n="1">
           <p n="1">Once upon a time...</p>
       </section>
   </chapter>
   <chapter n="2">
       <note n="1">I am still waiting for my $100000 advance.</note>
       <section n="1">
           <p n="1">... and they lived happily ever after.</p>
       </section>
   </chapter>
</doc>


doc2.xml ====== <doc> <chapter n="1"> <section n="1.A"> <p n="1">Once upon a time...</p> </section> </chapter> <chapter n="2.A"> <note n="1">I am still waiting for my $100000 advance.</note> <section n="1"> <p n="1">... and they lived happily ever after.</p> </section> </chapter> </doc>


And I'd like doc3.xml = doc2.xml \ doc1.xml to yield: ====== <doc> <chapter n="1"> <section n="1.A"> </section> </chapter> <chapter n="2.A"> </chapter> </doc>

Here I'm using "value semantics" for node equality--meaning 2 nodes are considered equal, even if from different documents, if they have the same namespace, local-name, and number and values of attributes. Let's assume the same namespace(s).

Of course, one could make a case that the criteria for node equality should be extended to mandate that descendent nodes of each node also compare equal respectively. I suppose this would be a more orthogonal view, since then doc3.xml above really shows all "changed" nodes: <doc> is present not just as context; it's present because <doc> in doc2.xml is changed from <doc> in doc1.xml by virtue of having changed descendent(s).

Thus far I've been able to determine the changed leaf nodes (this is pretty much straight from "XSLT Cookbook", Chapter 7), and to write a template to "print the branch" for each changed node. However I haven't been able to "superimpose" or "union" these separate branches to get 1 output doc. I'm possibly going about it all wrong, and hence the need to hunker down with books.

But if somebody could suggest how I may tackle this, please do.

And if seeing any templates I've written would help I'll be glad to post them. This is my first post to this (or any) XSLT list, and I don't want to lenghthen an already long note.

Thanx

--A

_________________________________________________________________
Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.