XPath Functions

XPath provides a function library that can manipulate or return four data types—node-sets, Boolean values, strings, and numbers. This section briefly looks at how two of those functions can be used.

The position() Function

The position() function is widely used. Suppose that you have an XML document similar to the following:

<book> 
<title>Sams Teach Yourself XML in 10 Minutes</title> 
<chapter number="1" title="What is XML?"> 
<!-- The text of Chapter 1 could go here --> 
</chapter> 
<chapter number="2" title="The Structure of an XML document"> 
<!-- The text of Chapter 2 could go here --> 
</chapter> 
<!-- Other <chapter> elements and their content would go 
  here --> 
</book> 

You might want to select the chapter element node that ...

Get Sams Teach Yourself XML in 10 Minutes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.