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

+numeric

-

Unary minus

Numbers

-numeric

Table: unary operators.

Binary operators

Operator

Name

Domain

+

Addition

Numbers, date values

numeric + numeric
-> numeric

xs:date + xs:yearMonthDuration 
->xs:date

xs:date + xs:dayTimeDuration 
->xs:date

xs:time + xs:dayTimeDuration 
->xs:time

xs:datetime + xs:yearMonthDuration 
-> xs:dateTime

xs:datetime + xs:dayTimeDuration 
-> xs:dateTime

xs:yearMonthDuration + xs:yearMonthDuration 
-> xs:yearMonthDuration

xs:dayTimeDuration + xs:dayTimeDuration
-> xs:dayTimeDuration 

-

Subtraction

Numbers, date values

numeric – numeric 
-> numeric

xs:date – xs:date 
-> xs:dayTimeDuration

xs:date – xs:yearMonthDuration 
-> xs:date

xs:date – xs:dayTimeDuration 
-> xs:date

xs:time – xs:time 
-> xs:dayTimeDuration

xs:time – xs:dayTimeDuration 
-> xs:time

xs:datetime – xs:datetime 
-> xs:dayTimeDuration

xs:datetime – xs:yearMonthDuration 
-> xs:dateTime

xs:datetime – xs:dayTimeDuration 
-> xs:dateTime

xs:yearMonthDuration – xs:yearMonthDuration
-> xs:yearMonthDuration

xs:dayTimeDuration – xs:dayTimeDuration 
-> xs:dayTimeDuration

*

Multiplication

Numbers, date values

numeric * numeric
-> numeric

xs:decimal * xs:yearMonthDuration 
-> xs:yearMonthDuration

xs:decimal * xs:dayTimeDuration 
-> xs:dayTimeDuration

div

Division

Numbers, date values

numeric div numeric
-> numeric

xs:integer div xs:integer
-> xs:decimal

xs:yearMonthDuration xs:decimal
-> xs:yearMonthDuration

xs:dayTimeDuration xs:decimal
-> xs:dayTimeDuration

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

xs:boolean eq xs:boolean
-> xs:boolean

xs:string eq xs:string
-> xs:boolean

xs:date eq xs:date
-> xs:boolean

xs:time eq xs:time
-> xs:boolean

xs:dateTime eq xs:dateTime
-> xs:boolean

xs:yearMonthDuration eq xs:yearMonthDuration
-> xs:boolean

xs:dayTimeDuration eq xs:dayTimeDuration
-> xs:boolean

Gregorian eq Gregorian
-> xs:boolean

xs:hexBinary eq xs:hexBinary
-> xs:boolean

xs:base64Binary eq xs:base64Binary
-> xs:boolean

xs:anyURI eq xs:anyURI
-> xs:boolean

xs:QName eq xs:QName
-> xs:boolean

xs:NOTATION eq xs:NOTATION
-> xs:boolean

ne

Inequality

Numbers, Booleans, strings, dates, binary values, URI strings, QNames, notations

numeric ne numeric
-> xs:boolean

xs:boolean ne xs:boolean
-> xs:boolean

xs:string ne xs:string
-> xs:boolean

xs:date ne xs:date
-> xs:boolean

xs:time ne xs:time
-> xs:boolean

xs:dateTime ne xs:dateTime
-> xs:boolean

xs:yearMonthDuration ne xs:yearMonthDuration
-> xs:boolean

xs:dayTimeDuration ne xs:dayTimeDuration
-> xs:boolean

Gregorian ne Gregorian
-> xs:bool ean

xs:hexBinary ne xs:hexBinary
-> xs:boolean

xs:base64Binary ne xs:base64Binary
-> xs:boolean

xs:anyURI ne xs:anyURI
-> xs:boolean

xs:QName ne xs:QName
-> xs:boolean

xs:NOTATION ne xs:NOTATION
-> xs:boolean

gt

Greater than

Numbers, Booleans, strings, date values

numeric gt numeric
-> xs:boolean

xs:boolean gt xs:boolean
-> xs:boolean

xs:string gt xs:string
-> xs:boolean

xs:date  gt xs:date
-> xs:boolean

xs:time gt xs:time
-> xs:boolean

xs:yearMonthDuration gt xs:yearMonthDuration
-> xs:boolean

xs:dayTimeDuration gt xs:dayTimeDuration
-> xs:boolean

lt

Less than

Numbers, Booleans, strings, date values

numeric lt numeric
-> xs:boolean

xs:boolean lt xs:boolean
-> xs:boolean

xs:string lt xs:string
-> xs:boolean

xs:date lt xs:date
-> xs:boolean

xs:time lt xs:time
-> xs:boolean

xs:yearMonthDuration lt xs:yearMonthDuration
-> xs:boolean

xs:dayTimeDuration lt xs:dayTimeDuration
-> xs:boolean

ge

Greater than or equal to

Numbers, Booleans, strings, date values

numeric ge numeric
-> xs:boolean

xs:boolean ge xs:boolean
-> xs:boolean

xs:string ge xs:string
-> xs:boolean

xs:date ge xs:date
-> xs:boolean

xs:time ge xs:time
-> xs:boolean

xs:yearMonthDuration ge xs:yearMonthDuration
-> xs:boolean

xs:dayTimeDuration ge xs:dayTimeDuration
-> xs:boolean

le

Less than or equal to

Numbers, Booleans, strings, date values

numeric le numeric
-> xs:boolean

xs:boolean le xs:boolean
-> xs:boolean

xs:string le xs:string
-> xs:boolean

xs:date le xs:date
-> xs:boolean

xs:time le xs:time
-> xs:boolean

xs:yearMonthDuration le xs:yearMonthDuration
-> xs:boolean

xs:dayTimeDuration le xs:dayTimeDuration
-> xs:boolean

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-dayTimeDu­ration-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.

   

back to top