• +49-(0)721-402485-12
Your experts for XML, XQuery and XML Databases

Equality of sequences

On sequences no order relation is defined. But it is possible to test two sequences for equality. For this purpose, the fn:deep-equal() function is available. Since sequence may be heterogenous, the definition of the equality is really comprehensive.

In order that sequences are equal, they must have the same number of items, and the items at the same position of each sequence must be pairwise equal. With this, the empty sequence is equal to the empty sequence. For other sequences it must be defined when two items are equal:

If the two items are atomic values, the equality is defined via the eq operator. For this operator sorting orders play a role; therefore, with thehelp of the fn:deep-equal() function, a sorting order can be defined. If one of the two items is an atomic value and the other a node, they are not equal. The equality of nodes to one another is defined recursively:

  • The type of the nodes must be equal (e.g. attribute nodes).
  • If the nodes have names, the names must be equal.
  • If they are attribute nodes, the name and the typed value must be equal.
  • For text nodes, namespace nodes and comment nodes, the textual value must be equal.
  • For processing instruction nodes, the name and the textual value must be equal.
  • If they are element nodes, for the two nodes must apply that there exists for each attribute in the one node an attribute in the other node, so that the attribute nodes are equal.
  • If the two element nodes have a simple type, the typed value must be equal.
  • If an element node has a simple type and the other not, they are not equal.
  • If the two element nodes have a complex, possibly mixed content, they are equal if their child nodes (ignoring comment nodes and nodes for processing instructions) are pairwise equal, which means if for the two element nodes $e1 and $e2 applies:

fn:deep-equal($e1/(* | text()), $e2/(* | text()), $collation)

As a consequence, it is not required that for elements or attributes the type must be identical or that the nodes must originate from the same context. Nodes for processing instructions and comment nodes are obviously only taken into account when they appear on the highest level of the call of fn:deep-equal().

$seq1 as item()*,
$seq2 as item()*[,
$collation as string])
as xs:boolean
returns true if the two input sequences are equal
taking into account the sorting order.

Table: Equality of sequences


Source: "XQuery – Grundlagen und fortgeschrittene Methoden", dpunkt-Verlag, Heidelberg (2004)

<< backnext >>