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 XSL Transformations (XSLT) implementation. This documentation discusses these expression operators.

Operator

Description

and

Logical-and

or

Logical-or

not()

Negation

=

Equality

!=

Not equal

&lt; *

Less than

&lt;= *

Less than or equal

&gt; *

Greater than

&lt;= *

Greater than or equal

|

Set operation; returns the union of two sets of nodes

* Extended XPath method

The World Wide Web Consortium (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 for future compatibility.

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

Precedence

Operators

Description

1

( )

Grouping

2

[ ]

Filters

3

/

//

Path operations

4

< or &lt;

<= or &lt;=

> or &gt;

>= or &gt;=

Comparisons

5

=

!=

Comparisons

6

|

Union

7

not()

Boolean not

8

And

Boolean and

9

Or

Boolean or

When the operators are used in an XML document, such as an XSLT style sheet, the < and > tokens must be escaped as &lt; and &gt;, respectively. For example, the following XSLT instruction invokes an XSLT template rule on all <book> elements whose <price> element has a numeric value less than or equal to 10.

When an XPath expression is used with DOM, the < and > operators need not to be escaped. For example, the following JScript statement selects all <book> elements whose <price> element has a numeric value less than or equal to 10.

Logical-and and Logical-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 sophisticated logical expressions.

Examples

Expression

Refers to

author[degree and award]

All <author> elements that contain at least one <degree> element and at least one <award> element.

author[(degree or award) and publication]

All <author> elements that contain at least one <degree> or <award> element, and at least one <publication> element.

Boolean not

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

Examples

Expression

Refers to

author[degree and not(publication)]

All <author> elements that contain at least one <degree> element, but contain no <publication> elements

author[not(degree or award) and publication]

All <author> elements that contain at least one <publication> element, but do not contain any <degree> elements or <award> elements.