1. 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.
    1. 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.
      2forThe 'for' operator is used in 'for' expressions to iterate over items in a sequence.
      2letThe 'let' operator is used for assigning variables in 'let' expressions.
      2some, everyThe 'some' and 'every' operators are used in quantified expressions.
      2ifThe 'if' operator is used in conditional expressions.
      3orThe 'or' operator is used in logical expressions.
      4andThe 'and' operator is used in logical expressions.
      5eq, ne, lt, le, gt, geThe '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.
      5is, <<, >>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.
      7toThe '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, modThe '*', '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.
      10union, |The 'union' operator which is symbolized by 'union' or '|' is used in sequence combining expressions.
      11intersect, exceptThe 'intersect' and 'except' operators are used in sequence combining expressions.
      12instance ofThe 'instance of' operator is used in expressions on 'sequenceTypes'.
      13treat asThe 'treat as' operator is used in expressions on 'sequenceTypes'.
      14castable asThe 'castable as' operator is used in expressions on 'sequenceTypes'.
      15cast asThe '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.
      1. New operators in XPath 3.0

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

        1. 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.
        2. 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.