Version 8.2.2
 —  X-Query Reference Guide  —

BetweenExpr

Select nodes based on a value range.


Syntax

BetweenExpr

SequenceExpr | SequenceExpr (between | betw) Number, Number |  SequenceExpr (between | betw) Literal, Literal

Top of page

Description

You can select nodes based on a value range, with the limiting values separated by a comma. The range is inclusive of the limiting values. If the first value is larger than the second, the values are implicitly exchanged. The comparison depends on the datatype of the node. If you compare a string value (Literal) with a string range, then a lexical comparison is performed using the lexicographical order. If you compare a string value with a numeric range or a numeric value with a string range, then any string values are implicitly converted to numbers and a numeric comparison takes place. If the string cannot be converted to a numeric value, then the conversion yields the special value "NaN" and the comparison fails.

You can think of BetweenExpr as a convenient abbreviation for logical conjunctions of RelationalExpr, see the compatibility note for an example.

You can use betw as a shorthand for between. However, both variants must be input in lower case.

Top of page

Compatibility

There is no BetweenExpr defined in XPath. For numeric values, you can simulate this by using relational expressions. The second example below could be rewritten as:

//doctor[@pager >= 2 and @pager <= 5]

As RelationalExpr restricts comparison to numeric values, you cannot in general formulate an equivalent XPath expression for the first example.

Number and Literal correspond to the respective XPath expressions, as defined in the Section 3.7, Rules 30 and 29.

Top of page

Examples

Tip:
Use BetweenExpr instead of AndExpr where possible. Usually a query such as //patient[born between 1950, 1953] is much more efficient than the equivalent query expression //patient[born > 1949 and born < 1954].

Top of page

Related Expressions

SequenceExpr

Top of page