# Operators

In programming languages an

**operator**is a symbol or keyword which represents a specific action.An example of an operator is the '+' symbol which adds two operands together.

An

**operand**is an object upon which the operator operates.5 > 3

In the example expression above, the integers 5 and 3 are the operands and '>' is the operator.## XPath Operators

The table below lists the XPath 3.0 operators in order of increasing operator precedence (with 1 being the operator with the lowest precedence and 19 the operator with the highest precedence). Operator precedence determines the order in which operators are evaluated.

1 , The comma ',' operator is used in sequence expressions to construct a sequence. 2 for The 'for' operator is used in 'for' expressions to iterate over items in a sequence. 2 let The 'let' operator is used for assigning variables in 'let' expressions. 2 some, every The 'some' and 'every' operators are used in quantified expressions. 2 if The 'if' operator is used in conditional expressions. 3 or The 'or' operator is used in logical expressions. 4 and The 'and' operator is used in logical expressions. 5 eq, ne, lt, le, gt, ge The 'eq', 'ne', 'lt', 'le', 'gt' and 'ge' operators are used in value comparisons. These symbols stand for 'equal', 'not equal', 'less than', 'less than or equal', 'greater than' and 'greater than or equal' respectively. 5 =, !=, <, <=, >, >= The '=' , '!=', '<', '<=', '>', '>=' operators are used in general comparisons. These symbols stand for 'equal', 'not equal', 'less than', 'less than or equal', 'greater than' and 'greater than or equal' respectively. 5 is, <<, >> The 'is', '<<' and '>>' operators are used in node comparisons. 6 || The concat operator '||' was introduced in XPath 3.0. It used in string concatenation expressions to concatenate two strings. 7 to The 'to' operator is used in sequence expressions to construct a sequence of items of type 'xs:integer' from a range specified by the left and right operands. 8 +, - (binary) The '+' and '-' operators i.e. addition and subtraction, are used in arithmetic expressions and operate on two operands. 9 *, div, idiv, mod The '*', 'div', 'idiv' and 'mod' operators i.e. multiplication, division, integer division (rounds result to integer) and modulo (returns remainder of division) operators are used in arithmetic expressions. 10 union, | The 'union' operator which is symbolized by 'union' or '|' is used in sequence combining expressions. 11 intersect, except The 'intersect' and 'except' operators are used in sequence combining expressions. 12 instance of The 'instance of' operator is used in expressions on 'sequenceTypes'. 13 treat as The 'treat as' operator is used in expressions on 'sequenceTypes'. 14 castable as The 'castable as' operator is used in expressions on 'sequenceTypes'. 15 cast as The 'cast as' operator is used in expressions on 'sequenceTypes'. 16 +, - (unary) The '+' and '-' operators can be used in unary form to denote positive or negative values. 17 ! The '!' operator known as the 'map' operator is new to XPath 3.0 and is similar in funcionality to a 'for' expression. 18 /, // The '/' and '//'operators are used in location path expressions. 19 [ ] The '[ ]' operator is used to denote a predicate. ### New operators in XPath 3.0

There are two new operators in XPath 3.0, the concat operator '||' and the map operator '!'.

#### Concat operator

The '||' operator is convenient because it is no longer necessary to call the concat function to concatenate two strings.

concat('hello', ' world')

result:('hello world')

This example shows the conventional way of concatenating strings by calling the 'concat' function'hello' || ' world'

result:('hello world')

This example shows how to concatenate strings by using the '||' operator. This is a much simpler syntax than having to explicitly call the built-in 'concat' function.#### Map operator

The ''!' operator is similar to a 'for' expression. It allows us to process items in a sequence.

for $i in /employee/person/name return 'Hi ' || $i

result:('Hi Mary', 'Hi Peter', 'Hi Mark')

This example shows how to process each item in a sequence by using a 'for' expression./employee/person ! ('Hi ' || .)

result:('Hi Mary', 'Hi Peter', 'Hi Mark')

This example shows an alternate way of processing each item in a sequence by using the '!' operator. Using the map operator is less verbose and it is not necessary to bind variables as in the 'for' expression.