XML technologies / XSLT / XSLT Cookbook / XPath

(Excerpt from "XSLT Kochbuch" by Sal Mangano)

"Neo, one day you will understand, as I do, that there is a difference
between knowing the path and walking it."

Morpheus (The Matrix)

Introduction

XPath is an expression language essential to XML processing. Just as you cannot master English without learning the alphabet, you cannot master XSLT without XPath. Several readers of the first edition of the XSLT Cookbook challenged me for omitting XPath. This chapter was added partly to satisfy them, but mainly because the latest XPath 2.0 specifications are far more powerful. Many recipes can nevertheless also be used with XPath 1.0.

In XSLT 1.0, XPath has three crucial roles:

  1. it is used within templates for addressing within a document from which data is extracted during transformation.

  2. XPath syntax acts as the pattern language in template matching rules.

  3. it performs simple calculations and string manipulation through built-in XPath operators and functions.

XSLT 2.0 maintains and strengthens this close relationship with XPath 2.0 by making extensive use of its new computational capabilities. One might even say that XSLT 2.0’s improvements stem mainly from advances in XPath 2.0. These include sequences, regular expressions, conditional and iterative expressions, an extended type system conforming to XML Schema and many new built-in functions.

Each recipe in this chapter is a set of smaller recipes addressing classes of XPath problems often encountered with XSLT. We comment on each XPath expression using XPath 2.0’s comment syntax (: Kommentar :), but XPath/XSLT 1.0 users should remember that these comments are not valid 1.0 syntax. To show an empty XPath result, we write ( ), the notation for an actually empty sequence in XPath 2.0.

  

  

 

 

 

back to top