[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Simple XML Diff
Subject: Re: [xsl] Simple XML Diff From: "Darcy Parker" <darcyparker@xxxxxxxxx> Date: Thu, 10 Jul 2008 16:40:47 -0400 |
Have you looked at this extension? http://www.exslt.org/set/functions/difference/index.html You should be able to use it with most XSLT 1.0 processors. My first impression is that it would be feasible to write an XSL that reads in 2 documents and then starting at the root of each document step through each level of elements and filter out differences. If you find a difference, step through those nodes recursively in order to pin point the difference. Darcy On Thu, Jul 10, 2008 at 4:17 PM, Mark Anderson <mark.anderson@xxxxxxxxxxxxxxxxxxx> wrote: > Hi All > > I'm trying to write an XML template that will compare two XML files that have *identical* structures. I thought it would be easy or in the archives, but all I can find is references to full DIFF functions that look for new elements, etc. > > My style sheet and an XML file (let's call it "new.xml") will get called from a 32-bit windows app and it needs to transform the XML to HTML. > > My stylesheet will contain a reference to a "master" xml doc (let's call it "master.xml"). > > What I need to do is compare every element an attribute in new.xml with the equivalent in master.xml and then highlight differences (the easy bit). What I'm stuck with is something that (I'm guessing) is dead easy, but I can't figure it out: how to iterate through all elements and attributes in new.xml and find the equivalent in master.xml. > > Example > > "New.xml" > <nodeA attribute1="XXX" attribute2="YYY"> > <nodeA1>ZZZ</nodeA1> > </nodeA> > <nodeB>AAA</nodeB> > <nodeC>BBB</nodeC> > > "Master.xml" > <nodeA attribute1="111" attribute2="222"> > <nodeA1>FFF</nodeA1> > </nodeA> > <nodeB>AAA</nodeB> > <nodeC>BBB</nodeC> > > So, this XSLTemplate I need to create needs to compare > > New.xml/nodeA/@attribute1 to Master.xml/nodeA/@attribute1 > New.xml/nodeA/nodeA1 to Master.xml/nodeA/nodeA1 > > I'm guessing there's a single apply-templates element I can use that will do this. The contents of this will be writing either HMTL listing all the elements that do no match in the two files. I don't anticipate a problem with this. > > So the output would say something like: > New.xml/nodeA/@attribute1 = XXX - Master.xml/nodeA/@attribute1 = 111 > New.xml/nodeA/nodeA1 = ZZZ - Master.xml/nodeA/nodeA1 = FFF > > Ideally, I'd like to ignore certain elements (like creation date and time fields) as they will always be different between New.xml and Master.xml > > I have to use XSLT1.0 for this > > Could someone point me in the right direction? > > Thanks > > Mark
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Simple XML Diff, Mark Anderson | Thread | Re: [xsl] Simple XML Diff, Michael Ludwig |
[xsl] Simple XML Diff, Mark Anderson | Date | Re: [xsl] Validation XSLT using XSL, Ganesh Babu N |
Month |