Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
If two items in corresponding positions are nodes, then to be deep-equal they must satisfy a number of conditions:
Nodes can be deep-equal even if they differ in certain respects:
Surprisingly, however, whitespace text nodes are taken into account even within an element that has an element-only content model. Furthermore, although comments and processing instructions appearing as children of an element are not compared directly, their presence can affect the result because they split a text node into two: so
and
are not deep-equal.
Examples
Expression | Result |
deep-equal((1,2,3), (1,2,3)) | true |
deep-equal((1,2,3), (3,2,1)) | false |
deep-equal((1,2), (1.0, 2.0)) | true |
deep-equal((), ()) | true |
In the following examples, assume that
$doc
refers to the following document:
and assume that
$weak
refers to a collation under which
c
and
C
compare as equal. Then:
Expression | Result |
deep-equal($doc/e[1], $doc/e[2]) | false |
deep-equal($doc/e[1], $doc/e[3], $weak) | true |
deep-equal($doc/e[1]/@*, $doc/e[2]/@*, $weak) | Undefined (the result depends on the order of attribute nodes , which is unpredictable) |
Usage
The
deep-equal()
function represents one particular way of deciding whether two nodes or sequences are equal to each other. In practice there are probably two common ways it is likely to be used:
Note that comparing two element nodes using the
=
or
eq
operators fails if the elements are defined in the schema to have a complex type, unless this is a complex type allowing mixed content, in which case the elements are compared by comparing their string values.
The definition of deep equality for nodes is one that will suit some tastes and not others. For example, it treats comments and processing instructions within an element as insignificant, but whitespace between elements as significant. It also treats the order of child elements (but not attributes) as significant. If you don't like this definition, the answer is simple: define your own function, and use that instead.
Saxon provides a function
saxon:deep-equal()
which is modeled on the standard
deep-equal()
function, but provides an extra argument allowing user control over the way in which the comparison is performed. Details are at
http://www.saxonica.com/documentation/extensions/functions/deepequal.html
.
default-collation
The
default-collation()
function returns the URI of the default collation, that is, the collation that is used when no collation is explicitly specified in a function such as
compare()
.
Signature
This function takes no arguments.
Type | Meaning | |
Result | xs:string | The URI of the default collation from the runtime context |
Usage
The
default-collation()
function is useful when you want to assign a collation conditionally, for example: