XML technologies / XSLT / XSLT and XPath functions / XPath 2.0 operator functions
(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, chapter 5.)
XPath 2.0’s strictly formal operator functions, identified by the prefix op:, describe in function form the definitions underlying the operators (operator symbols) used in XPath 1.0 and XPath 2.0.
No namespace for prefix op:
The prefix op: is not bound to a namespace. These functions are not intended for direct use; they merely clarify how XPath operators behave with different data types.
The specifications explicitly do not require applications to provide actual implementations of these functions.
Supported operator symbols
The following table lists XPath operators for which operator functions exist. A detailed list of the functions themselves is unnecessary here.
Unary operators
Operator | Name | Domain |
|---|---|---|
+ | Unary plus | Numbers
|
- | Unary minus | Numbers
|
Table: unary operators.
Binary operators
Operator | Name | Domain |
|---|---|---|
+ | Addition | Numbers, date values numeric + numeric xs:date + xs:yearMonthDuration xs:date + xs:dayTimeDuration xs:time + xs:dayTimeDuration xs:datetime + xs:yearMonthDuration xs:datetime + xs:dayTimeDuration xs:yearMonthDuration + xs:yearMonthDuration xs:dayTimeDuration + xs:dayTimeDuration |
- | Subtraction | Numbers, date values numeric – numeric xs:date – xs:date xs:date – xs:yearMonthDuration xs:date – xs:dayTimeDuration xs:time – xs:time xs:time – xs:dayTimeDuration xs:datetime – xs:datetime xs:datetime – xs:yearMonthDuration xs:datetime – xs:dayTimeDuration xs:yearMonthDuration – xs:yearMonthDuration xs:dayTimeDuration – xs:dayTimeDuration |
* | Multiplication | Numbers, date values numeric * numeric xs:decimal * xs:yearMonthDuration xs:decimal * xs:dayTimeDuration |
div | Division | Numbers, date values numeric div numeric xs:integer div xs:integer xs:yearMonthDuration xs:decimal xs:dayTimeDuration xs:decimal |
idiv | Integer division | Integers xs:integer idiv xs:integer -> xs:integer |
to | Integer range | Integers xs:integer to xs:integer -> xs:integer* |
mod | Modulo | Numbers numeric mod numeric -> numeric |
eq | Equality | Numbers, Booleans, strings, dates, binary values, URI strings, QNames, notations numeric eq numeric xs:boolean eq xs:boolean xs:string eq xs:string xs:date eq xs:date xs:time eq xs:time xs:dateTime eq xs:dateTime xs:yearMonthDuration eq xs:yearMonthDuration xs:dayTimeDuration eq xs:dayTimeDuration Gregorian eq Gregorian xs:hexBinary eq xs:hexBinary xs:base64Binary eq xs:base64Binary xs:anyURI eq xs:anyURI |
ne | Inequality | Numbers, Booleans, strings, dates, binary values, URI strings, QNames, notations numeric ne numeric xs:boolean ne xs:boolean xs:string ne xs:string xs:date ne xs:date xs:time ne xs:time xs:dateTime ne xs:dateTime xs:yearMonthDuration ne xs:yearMonthDuration xs:dayTimeDuration ne xs:dayTimeDuration Gregorian ne Gregorian xs:hexBinary ne xs:hexBinary xs:base64Binary ne xs:base64Binary xs:anyURI ne xs:anyURI xs:QName ne xs:QName xs:NOTATION ne xs:NOTATION |
gt | Greater than | Numbers, Booleans, strings, date values numeric gt numeric xs:boolean gt xs:boolean xs:string gt xs:string xs:date gt xs:date xs:time gt xs:time xs:yearMonthDuration gt xs:yearMonthDuration xs:dayTimeDuration gt xs:dayTimeDuration |
lt | Less than | Numbers, Booleans, strings, date values numeric lt numeric xs:boolean lt xs:boolean xs:string lt xs:string xs:date lt xs:date xs:time lt xs:time xs:yearMonthDuration lt xs:yearMonthDuration xs:dayTimeDuration lt xs:dayTimeDuration |
ge | Greater than or equal to | Numbers, Booleans, strings, date values numeric ge numeric xs:boolean ge xs:boolean xs:string ge xs:string xs:date ge xs:date xs:time ge xs:time xs:yearMonthDuration ge xs:yearMonthDuration xs:dayTimeDuration ge xs:dayTimeDuration |
le | Less than or equal to | Numbers, Booleans, strings, date values numeric le numeric xs:boolean le xs:boolean xs:string le xs:string xs:date le xs:date xs:time le xs:time xs:yearMonthDuration le xs:yearMonthDuration xs:dayTimeDuration le xs:dayTimeDuration |
is | Is | Nodes node() is node() -> xs:boolean |
isnot | Is not | Nodes node() isnot node() -> xs:boolean |
except | Difference | Nodes node()* except node()* -> node()* |
intersect | Intersection | Nodes node()* intersect node()* -> node()* |
union | Union | Nodes node()* union node()* -> node()* |
| | Union | Nodes node()* | node()* -> node()* |
<< | Preceding node | Nodes node() << node() -> xs:boolean |
>> | Following node | Nodes node() >> node() -> xs:boolean |
, | Item separator | Items (sequences) item()* , item()* -> item()* |
Table: binary operators.
Explanation using the + operator
The + operator has several underlying operator functions that make it intuitively usable with dates as well as the usual numeric data types. The relevant operator function merely defines the procedure for the data types involved.
For completeness, an operator function is also declared for the familiar XPath 1.0 numeric use of the + operator. Here are three sample definitions:
op:add-dayTimeDuration-to-date($srcval1 as xs:date,
$srcval2 as xs:dayTimeDuration)
as xs:date
op:add-dayTimeDuration-to-dateTime($srcval1 as xs:dateTime,
$srcval2 as xs:dayTimeDuration)
as xs:dateTime
op:numeric-add($operand1 as numeric,
$operand2 as numeric)
as numeric
Other functions associated with the + operator include op:add-dayTimeDuration-to-time, op:add-dayTimeDurations, op:add-yearMonthDuration-to-date and op:add-yearMonthDuration-to-dateTime. Similar functions exist for the other operators in the table.
Copyright © Galileo Press, Bonn 2008
You may print the online version for private use.
Otherwise, this chapter from "XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch" is subject to the same terms as the bound edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn