RE: [xsl] Testing 2 XML documents for equality - a solution

Subject: RE: [xsl] Testing 2 XML documents for equality - a solution
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Wed, 30 Mar 2005 09:10:16 -0800 (PST)
Thanks a lot Mike for your observations.. I propose
this code to solve the attribute ordering problem you
cited (for both the documents).

<xsl:for-each select="$doc1//@*">
  <xsl:sort select="." />

i.e. adding a xsl:sort instruction in the for-each
loop. This shall solve this problem!

At the very start I said my stylesheet is catering
*strictly to XSLT 1.0* ! I am aware that XSLT 2.0
provides many new features which will help in better
ways to solve this problem.
I'll surely look at the deep-equals() spec in XSLT 2.0
, and the Canonical XML definition.. In fact I took a
cursory look at the Canonical XML spec sometime back.
*I feel my stylesheet caters to a large subset of
Canonical XML definition (I guess about 70-90%). Can
you please comment on my this claim? *

Also thanks for your other ideas..


--- Michael Kay <mike@xxxxxxxxxxxx> wrote:

> First you need to specify what you mean by equality.
> This is a difficult
> question. You could look to the spec of
> deep-equals() in XSLT 2.0 for
> guidance, or to the Canonical XML definition.
> There's scope for endless
> debate concerning issues such as comments,
> whitespace, namespace prefixes,
> unused namespace declarations, and so on.
> Your stylesheet will treat 
> <a x="1" y="2"/>
> and
> <a y="2" x="1"/>
> as being not equal, which is definitely wrong.
> Algorithms based on concatenating the contents of
> both documents and then
> comparing them as strings are likely to have the
> possibility of returning a
> false equality.
> An algorithm that uses recursive descent of both
> trees is likely to be much
> faster in the case where the trees aren't equal. 
> Michael Kay

Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site! 

Current Thread