Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Expression | Result |
M | True when min(M) < max(N) |
M<=N | True when min(M) <= max(N) |
M>N | True when max(M) > min(N) |
M>=N | True when max(M) >= min(N) |
Examples of General Comparisons
Expression | Description |
@width=3 | Tests whether the width attribute of the context node, after converting to a number, has the numeric value 3. If there is no width attribute, the result will be false. |
If the width attribute exists and is typed as numeric, the result will be true if and only if the numeric value is equal to 3. If the width attribute exists and is untyped, the result will be true if the width attribute can be converted to a number equal to 3; for example, if it is 3 or 3.00 . If the width attribute is defined in the schema as a list-valued attribute, then the result is true if any of the values in this list is equal to 3. | |
@width=(10, 20, 30) | Tests whether the width attribute has the value 10, 20, or 30. |
If the attribute is untyped, it is compared as a number. If the attribute is defined in the schema as being list-valued, then the comparison is true if any item in the list is equal to 10, 20, or 30. | |
@width !=$x | If there is no width attribute the result will be false. |
If the attribute width is untyped, then if the variable $x holds a numeric value, a numeric comparison is performed; if it holds a string value, a string comparison is performed. The result will be true if the values are different. | |
If the attribute width is typed, then an error will occur if the type is incompatible with the type of $x . | |
If $x holds a sequence, the result will be true if there is any item in the sequence whose typed value is not equal to the width attribute, using string comparison; it will be false if the sequence is empty. If the schema-defined type of the width attribute is a list type, then the comparison is performed with each item in that list considered individually. | |
count(*)>10 | Returns true if the context node has more than ten element children. |
sum(SALES)<10000 | Returns true if the sum of the numeric values of the |
position() | Returns true if the context position is less than half the context size, that is, if the position of this node is less than half way down the list of nodes being processed. |
not(//@temp<=0.0) | Returns true if all values of the temp attribute in the document are numeric, and greater than zero. |
Node Comparisons
This section describes the three operators
<<
,
is
, and
>>
, which are used to compare nodes. The
is
operator tests whether the two operands evaluate to the same node; the operators
<<
and
>>
test whether one node is before or after another in document order.