fn:deep-equal( $parameter1 as item()*, $parameter2 as item()*, [$collation as xs:string] ) as xs:boolean
This function assesses whether two sequences are deep-equal to each other. To be deep-equal, they must contain items that are pairwise deep-equal; and for two items to be deep-equal, they must either be atomic values that compare equal, or nodes of the same kind, with the same name, whose children are deep-equal. This is defined in more detail below. The $collation argument identifies a collation which is used at all levels of recursion when strings are compared (but not when names are compared), according to the rules in 7.3.1 Collations.
If the two sequences are both empty, the function returns true.
If the two sequences are of different lengths, the function returns false.
If the two sequences are of the same length, the function returns true if and only if every item in the sequence $parameter1 is deep-equal to the item at the same position in the sequence $parameter2. The rules for deciding whether two items are deep-equal follow.
Call the two items $i1 and $i2 respectively.
If $i1 and $i2 are both atomic values, they are deep-equal if and only if ($i1 eq $i2) is true. Or if both values are NaN. If the eq operator is not defined for $i1 and $i2, the function returns false.
If one of the pair $i1 or $i2 is an atomic value and the other is a node, the function returns false.
If $i1 and $i2 are both nodes, they are compared as described below:
If the two nodes are of different kinds, the result is false.
If the two nodes are both document nodes then they are deep-equal if and only if the sequence $i1/(*|text()) is deep-equal to the sequence $i2/(*|text()).
If the two nodes are both element nodes then they are deep-equal if and only if all of the following conditions are satisfied:
If the two nodes are both attribute nodes then they are deep-equal if and only if both the following conditions are satisfied:
If the two nodes are both processing instruction nodes or namespace bindings, then they are deep-equal if and only if both the following conditions are satisfied:
If the two nodes are both text nodes and their parent nodes are not object nodes, then they are deep-equal if and only if their string-values are both equal.
If the two nodes are both text nodes and their parent nodes are both object nodes, then they are deep-equal if and only if their keys and string-values are both equal.
If the two nodes are both comment nodes, then they are deep-equal if and only if their string-values are equal.
If the two nodes are both object nodes, then they are deep-equal if and only if all of the following conditions are satisfied:
If the two nodes are both boolean nodes, then they are deep-equal if and only if their keys and boolean values are equal.
If the two nodes are both number nodes, then they are deep-equal if and only if their keys and values are equal.
If the two nodes are both null nodes, they are deep-equal.
Notes:
The two nodes are not required to have the same type annotation, and they are not required to have the same in-scope namespaces. They may also differ in their parent, their base URI, and the values returned by the is-id and is-idrefs accesors (see Section 5.5 is-id Accessor[DM] and Section 5.6 is-idrefs Accessor[DM]). The order of children is significant, but the order of attributes is insignificant.
The following note applies to the Jan 2007 XQuery specification, but not to the May 2003 XQuery specification: The contents of comments and processing instructions are significant only if these nodes appear directly as items in the two sequences being compared. The content of a comment or processing instruction that appears as a descendant of an item in one of the sequences being compared does not affect the result. However, the presence of a comment or processing instruction, if it causes a text node to be split into two text nodes, may affect the result.
The result of fn:deep-equal(1, current-dateTime()) is false; it does not raise an error.
Assume $at := <attendees> <name last='Parker' first='Peter'/> <name last='Barker' first='Bob'/> <name last='Parker' first='Peter'/> </attendees> Then: fn:deep-equal($at, $at/*) returns false. fn:deep-equal($at/name[1], $at/name[2]) returns false. fn:deep-equal($at/name[1], $at/name[3]) returns true. fn:deep-equal($at/name[1], 'Peter Parker') returns false.