fn:deep-equal

Check for items in two arguments that compare equal in corresponding positions.

Top of page

Related Syntax Constructs

The following construct(s) refer to this construct:


Syntax

fn:deep-equal(item()* $param1, item()* $param2) => xs:boolean
fn:deep-equal(item()* $param1, item()* $param2, string $collation) => xs:boolean

Description

This function checks whether two sequences are deep-equal to each other. Deep equality means that the sequence must contain items that are pairwise deep-equal. Two items are deep-equal when they are either atomic values that compare equal or when they are nodes of the same kind with the same name whose children are deep-equal. More precisely, the following rules apply:

  • If the two sequences are 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 $param1 is deep-equal to the item at the same position in the sequence $param2. Two items $item1 and $item2 are deep-equal if one of the following rules holds:

    • If $item1 and $item2 are both atomic values, they are deep-equal if and only if ($item1 eq $item2) is true. They are also deep-equal, if both values are NaN. If the eq operator is not defined for $item1 and $item2, the function returns false.

    • If one item is an atomic value and the other is a node, false is returned.

    • If both are nodes the following applies: If they are nodes of different kind, the function returns false. Otherwise:

      Node Kind $item1 and $item2 are deep-equal, if and only if...
      document node the sequence $item1/(*|text()) is deep-equal to $item2/(*|text()).
      element node

      all of the following conditions hold:

      1. the two nodes have the same name, that is (node-name($item1) eq node-name($item2))

      2. the two nodes have the same number of attributes, and for every attribute $attr1 in $item1/@* there exists an attribute $attr2 in $item2/@* such that $attr1 and $attr2 are deep-equal. The order of attributes is not significant.

      3. One of the following holds: Both nodes have a type annotation that is either a simple type or a complex type with simple content, and the typed value of $item1 is deep-equal to the typed value of $item2. Or, one or both of the element nodes has a type annotation that is neither a simple type nor a complex type with simple content, and the sequence $item1/(*|text()) is deep-equal to the sequence $item2/(*|text()).

      attribute node the two nodes have the same name, that is (node-name($item1) eq node-name($item2)), and if the typed value of $item1 is equal to the typed value of $item2.
      processing instruction node the two nodes have the same name, that is (node-name($item1) eq node-name($item2)), and if the string value of $item1 is equal to the string value of $item2.
      namespace binding
      text node their string values are equal.
      comment node

You can also supply a collation argument that is used at all recursion levels where strings are compared.

Arguments

$param1

sequence

$param2

sequence

$collation

valid collation string literal

Examples

Consider the following expression and the subsequent calls of fn:deep-equal():

let $at := <attendees>
  <name last='Parker' first='Peter'/>
  <name last='Barker' first='Bob'/>
  <name last='Parker' first='Peter'/>
</attendees>
  • deep-equal($at, $at/*) returns false.

  • deep-equal($at/name[1], $at/name[2]) returns false.

  • deep-equal($at/name[1], $at/name[3]) returns true.

  • deep-equal($at/name[1], 'Peter Parker') returns false.