XPATH Expressions

All tutorials are implemented in text (here), and also with exercises and multimedia in the Tutorial Player. The main home page has a search engines, and more facilities.

Introduction
Function Calls
Node Sets
Boolean
Numbers
Strings
Lexical Structure
Summary

Introduction

This tutorial introduces XPath expressions and how numbers, strings, booleans, node-sets are used in expressions.

Location paths are expressions, but they are covered separately due to their importance in XPath.

Function Calls

A function call is an expression. The function name is used when any arguments. Arguments are converted prior to calling the function. The return from the function is therefore the return from the expression. Void functions are not available in XPath, and therefore this type of expression always returns a value

Node Sets

A location path can be used as an expression. Such an expression returns a set of nodes selected by the path. The "|" operator creates a union of two node sets.

Boolean

A boolean value usually results from a comparison in XPath. If node sets are compared, then their string values are compared, or number values.

Numbers

Numbers are floating point numbers in XPath. A number is a double precision 64 bit format IEEE 754. XPath uses positive and negative zero; and NaN (not a number). Operands acted upon by numeric operators are converted to numbers via the number function. The operators below are defined in XPath.

Operator   Behavior
+               addition
-               subtraction
div          floating-point division according to IEEE 754
mod          returns the remainder from a truncating division.

"-" is a legal caharacter in XML names, and therefore when subtract is used in XPath a whitespace before and after the "-" operator is recommended. Therefore,

operand1 - operand2 is the difference between the numeric values of these two operands.

Some examples of mod are below:

Strings

Strings consists of characters. A character in XPath corresponds to a single Unicode abstract character with a scalar Unicode value. This is not identical to a 16-bit Unicode code value.

the = operators is used, but results can be misleading unless the characters in the XML document are normalized into a canoncial form. This is because accented characters can be represented in precomposed or decomposed form.

Lexical Structure

The longest token is returned, when tokenizing. Whitespace is permitted in expressions.

Summary

This tutorial introduced XPath expressions, and how numbers, strings, booleans, and node-sets are used in expressions.