O'Reilly logo

XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition by Michael Kay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8. XPath: Operators on Items

This chapter defines the simple operators available for use in XPath expressions. This is inevitably a rather arbitrary category, but these operators seem to have enough in common to justify putting them together in one chapter. All these operators return single items (as distinct from sequences) — in fact, all of them except the arithmetic operators in the first section return a boolean result.

More specifically, this chapter describes the following families of operators:

  • Arithmetic operators, «+», «−», «*», «div», and «mod»

  • Value comparison operators «eq», «ne», «lt», «le», «gt», «ge»

  • General comparison operators «=», «!=», «<», «<=», «>», «>=»

  • Node comparison operators «<<», «is», and «>>»

  • Boolean operators «and» and «or»

Many of these operators behave in much the same way as similar operators in other languages. There are some surprises, though, because of the way XPath handles sequences, and because of the way it mixes typed and untyped data. So don't skip this chapter just because you imagine that everything about these operators can be guessed.

Arithmetic Operators

These operators are normally used to perform calculations on numbers, which may be of any of the numeric types: xs:integer, xs:decimal, xs:float, or xs:double. They are also overloaded to perform calculations on dates and durations.

Note that this section only describes arithmetic operators built in to the XPath syntax. These operators are complemented by a range of arithmetic functions ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required