UNDERSTANDING XPATH

XPath, or XML Path Language, is one of those things that takes a while to grasp, at least for most developers. It's been compared to regular expressions, which in my opinion is a bit much because it's not nearly that complicated. XPath is a query language for selecting nodes from an XML document source. In the Umbraco scenario, you use XPath as part of the XSLT to target nodes from the umbraco.config (XML cache) mentioned earlier in this chapter. In a nutshell, XPath allows you to traverse any node structure by providing a set of steps that make up a path, or more complex instructions to programmatically manipulate the output from the source XML. To illustrate the concept, before you dig into the practicals of using XPath in Umbraco, take a look at Listing 11-1 as a basis for the following XPath examples. This is an abbreviation of the classic book.xml example that you see in most XSL/XPath examples on the Internet.

LISTING 11-1: books.xml

image
<?xml version=“1.0”?> <catalog> <book id=“bk101”> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> <book id=“bk102”> <author>Ralls, Kim</author> <title>Midnight Rain</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-12-16</publish_date> ...

Get Umbraco User's Guide 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.