[xsl] Comparing two xml documents

Subject: [xsl] Comparing two xml documents
From: "Ragulf Pickaxe" <jawxml@xxxxxxxxxxx>
Date: Wed, 12 Mar 2003 15:48:33 +0000
Hello all,

I have two flat xml documents, that I want to compare - let's call them A and B.
I know only the root element of the two documents, all other elements are unknown to me. Only thing is that there are no attributes in the two documents - the elements might be empty or they might not - and that the elements in a given document are unique in name.


The comparisson is both between the contents between two elements of the same name, and finding the elements that are only in one of the documents.

Is there any way to achieve this?

I would imagine matching all elements in A, for each match looking for the element in B. If match is found, then comparing the value, if no match is found then marking this. Then I would go to B and look through all these elements, marking all elements that are not in A.

The problem is, I don't know how to do this, using XSL.

I have a scetch here, with comments on all my problems. Any help would be greatly appreciated:

<!-- Doing the transformation on A -->
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:variable name="B" select="document('B.xml')"/>


 <xsl:template match="/">
   <xsl:apply-templates select="RootElement">
 </xsl:template>

 <xsl:template match="RootElement">
   <xsl:apply-templates/>
 </xsl:template>

<xsl:template match="*"> <!-- Does this match all elements? -->
<!-- Here I would like to be able to search for the element with the same name as the chosen one -->



<xsl:apply-templates select="$B/RootElement"/> <!-- Would this select the RootElement of B? -->
</xsl:template>


 <xsl:template match="$B/RootElement">
   <xsl:apply-templates/>
 </xsl:template>

<xsl:template match="$B/*"> <!-- Does this match the given elements in document B? -->
<!-- And here I want to check whether the element exists in document A. Will I need a variable for that document? And how would I do that, if needed? -->
</xsl:template>



</xsl:transform>



I hope it is possible to do something like this.


Thanks!

Ragulf Pickaxe :)

_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread