Home > Online Product Documentation > Table of Contents > Specifying Boolean Expressions and Functions
This section provides information on how to specify Boolean expressions and functions in queries. It includes the following topics:
You can specify Boolean expressions in the subqueries in filters. You specify the Boolean
AND,
OR, and
NOT operators like this:
You can use parentheses to group collection specifications and operators for clarity or where the normal precedence is inadequate to express an operation.
Operators are case sensitive. Spaces are not significant. You can omit them or include them for clarity.
The following query returns all authors who have at least one degree and one award:
The next query finds all authors who have at least one degree or award and at least one publication:
Following is a query that finds all authors who have at least one degree and no publications:
This section describes the Boolean functions that you can call in a query. The operations you can perform are
In some situations, you might want to force a Boolean comparison. The XPath processor performs a Boolean comparison if either operand is a Boolean value. Consequently, if neither operand is a Boolean value, call the
boolean() function on one operand to convert it to a Boolean value. The XPath processor automatically converts the other operand to a Boolean value. The format of the
boolean() function is
The
boolean() function converts its argument to Boolean as follows:
The
boolean() function is useful in comparisons. For example, the following query returns
b elements that either contain both
c and
d elements as children or contain neither
c nor
d elements as children:
This query is equivalent to the following query:
To obtain the opposite Boolean value, call the
not() function. The format is
The
not() function returns
true if its argument is
false, and returns
false if its argument is
true. For example, the following query finds all authors who have publications but no degrees or awards:
To obtain the value
true, call the
true() function. The format is
The
true() function returns
true.
To obtain the value
false, call the
false() function. The format is
The
false() function returns
false.
To determine whether the language of the context node is the language you expect it to be, call the
lang() function. The format is
The
lang() function returns
true or
false depending on whether the language of the context node as specified by the
xml:lang attribute is the same as, or is a sublanguage of, the language specified by the argument string. The language of the context node is determined by the value of the
xml:lang attribute on the context node or, if the context node has no
xml:lang attribute, by the value of the
xml:lang attribute on the nearest ancestor of the context node that has an
xml:lang attribute.
If there is no such attribute, then
lang() returns
false. If there is such an attribute,
lang() returns
true in the following situations:
In both situations, case is ignored. For example:
This returns
true if the context node is any of these elements: