O'Reilly logo

Beginning XSLT and XPath: Transforming XML Documents and Data by Ian Williams

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 2. Introducing XPath

XPath 2.0 is an expression language that is absolutely fundamental to XSLT 2.0 in several important ways.

A common use of XPath in XSLT is selecting nodes in an XML document. For example, you can make a very wide selection and refer to all the <li> elements in a document using the expression select="//li", or be very specific by pointing to the class attribute in the first <p> in the third <div> of a document using div[3]/p[1]/@class.

XPath expressions are also used by an XSLT processor to match source tree nodes to template rules. As the XSLT processor traverses the element nodes in an XML source document, it looks for a corresponding XPath expression that you set in the match attribute of an <xsl:template> declaration.

XPath functions provide you with a wide range of features, enabling you to manipulate strings, dates and times, numbers, and nodes.

In this chapter you take a break from creating full-scale stylesheets and look into some XPath 2.0 features in some detail. You'll do all of the following:

  • Review node types and properties.

  • Look at the XPath data model.

  • Tackle the important topic of path expressions used to navigate the node trees in your source documents.

  • Get a brief overview of using the XPath Analyzer—a tool that can help you avoid problems along the XPath trail.

  • Study a rich set of XPath functions that you will encounter repeatedly as you develop your XSLT skills.

Nodes

In the introduction you saw that XPath models the XML document as a tree of ...

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