DB2 Version 9.7 for Linux, UNIX, and Windows

deep-equal function

The fn:deep-equal function compares two sequences to determine whether they meet the requirements for deep equality.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-fn:deep-equal(sequence-1,sequence-2)------------------------><

sequence-1, sequence-2
The sequences that are to be compared. The items in each sequence can be atomic values of any type, or nodes.

Returned value

The returned value is the xs:boolean value true if sequence-1 and sequence-2 have deep equality. Otherwise the returned value is false.

If sequence-1 and sequence-2 are the empty sequence, they have deep equality.

If two sequences are not empty, the two sequences have deep equality if they satisfy both of the following conditions:
  • The number of items in sequence-1 is equal to the number of items in sequence-2.
  • Each item in sequence-1 (item-1) satisfies the conditions for deep equality to the corresponding item in sequence-2 (item-2). item-1 and item-2 have deep equality if they satisfy either of the following conditions:
    • item-1 and item-2 are both atomic values and satisfy either of the following conditions:
      • The expression item-1 eq item-2 returns true
      • Both item-1 and item-2 have the type xs:float or xs:double and the value NaN.
    • item-1 and item-2 are both nodes of the same kind and satisfy the conditions for deep equality in the following table.
      Table 1. Deep equality for nodes in a sequence
      Node kind of both item-1 and item-2 Conditions for deep equality
      Document The sequence of the text and element children of item-1 is deep-equal to the sequence of the text and element children of item-2.
      Element All of the following conditions must be true:
      • item-1 and item-2 have the same name, which means that their namespace URIs match and their local names match. Namespace prefixes are ignored. Name matching is done using a binary comparison.
      • item-1 and item-2 have the same number of attributes, and every attribute of item-1 is deep-equal to an attribute of item-2.
      • One of the following conditions is true:
        • Both nodes are either unvalidated or validated with a type that permits mixed content (both text and child elements), and the sequence of the text and element children of item-1 is deep-equal to the sequence of the text and element children of item-2.
        • Both nodes are validated with a simple type (such as xs:decimal) or a type that has simple content (such as a "temperature" type whose content is xs:decimal), and the typed value of item-1 is deep-equal to the typed value of item-2.
        • Both nodes are validated with a type that permits no content (neither text nor child elements).
        • Both nodes are validated with a type that permits only child elements (no text), and each child element of item-1 is deep-equal to the corresponding child element of item-2.
      Attribute All of the following conditions must be true:
      • item-1 and item-2 have the same name, which means that their namespace URIs match and their local names match. Namespace prefixes are ignored. Name matching is done using a binary comparison.
      • The typed value of item-1 is deep-equal to the typed value of item-2.
      Text The content property values are equal when compared as strings with the eq operator using the default collation.
      Comment The content property values are equal when compared as strings with the eq operator using the default collation.
      Processing instruction All of the following conditions must be true:
      • item-1 and item-2 have the same name.
      • The content property values are equal when compared as strings with the eq operator using the default collation.

Example

The following function compares the sequences (1,'ABC') and (1,'ABCD') for deep equality. String comparisons use the default correlation.

fn:deep-equal((1,'ABC'), (1,'ABCD'))

The returned value is false.