The deep-equal() function would appear to do what you need.
 

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay



From: Vanfleet, David [mailto:david.vanfleet@siemens.com]
Sent: 22 March 2010 22:06
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Deep compare of two elements

Hi, I need to be able to do a deep compare two elements structures to determine if they are the same. For the elements to be the same they need to:

 

·         Contain the same element names in the same order

·         Contain the same element values

·         Contain the same attribute values

 

For example if I have the following 3 nodes:

 

<!-- $node1 -->

<element id=”one”>

<package>pac1</package>

<version>ver1</version>

</element>

 

<!-- $node2 -->

<element id=”one”>

<package>pac1</package>

</element>

 

<!-- $node3 -->

<element id=”one”>

<package>pac1</package>

<version>ver1</version>

</element>

 

I need to determine that:

 

                $node1 is NOT equal to $node2

 

And

 

$node1 IS equal to $node3

 

I know that I can write a function that can manually check all of these values but my element structure can get much more complicated then what I’m showing in my examples so I would like to know if there is an easier way to do this. I have looked at the <<is>> and <<=>> operators but they don’t give me what I need. Any help would be greatly appreciated.

 

Regards,

David