Microsoft XML SDK 2.6 - XSLT Reference

Boolean, Comparison, and Set Expressions

Filter patterns can contain Boolean expressions, comparison expressions, and set expressions. Shortcuts listed in the following table represent alternative symbols that are provided in this XSLT implementation. This documentation discusses these expression operators.

Operator Description
and Logical-and
or Logical-or
not() Negation
= Equality
!= * Not equal
< * Less than
<= * Less than or equal
> * Greater than
>= * Greater than or equal
| Set operation; returns the union of two sets of nodes

* extended XPath method

The W3C syntax for operator keywords uses white space and other separators rather than the dollar sign character ($) used in version 2.5. In the W3C syntax, a binary keyword of the form $xxx$ can be expressed as wsxxxws, where ws refers to a token terminator that can be white space, single quote characters ('), or double quote characters ("). Unary operators such as not() use functional notation. Although the Microsoft implementation supports both syntaxes, it is recommended that the W3C syntax be used where possible in the interests of future compatibility.

Precedence order (from highest to lowest) for comparison operators and Boolean operators is shown in the following table:

1 ( ) Grouping
2 [ ] Filters
3 / // Path operations
4 < <= > >= Comparisons
5 = != Comparisons
6 | Union
7 not() Boolean not
8 and Boolean and
9 or Boolean or

Boolean expressions can match all nodes of a particular value or all nodes with nodes in particular ranges. Boolean expressions are in the form (left-side value operator right-side value) and return a Boolean result.

Operators are case sensitive.

Boolean AND and OR

The Boolean operators and and or perform logical-and and logical-or operations, respectively. These operators, in conjunction with grouping parentheses, can be used to build very sophisticated logical expressions.

Examples

Find all author elements that contain at least one degree and one award:

author[degree and award]

Find all author elements that contain at least one degree or award and at least one publication:

author[(degree or award) and publication]

Boolean NOT

The Boolean not operator negates the value of an expression within a filter pattern.

Examples

Find all author elements that contain at least one degree element and contain no publication elements:

author[degree and not(publication)]

Find all author elements that contain publication elements but do not contain either degree elements or award elements:

author[not(degree or award) and publication]

See Also

Sample Data | XPath Examples