Appendix B. XPath Reference
XPath is a well-established W3C specification that describes a non-XML syntax for selecting a set of nodes from the in-memory model of an XML document. XPath version 1.0 reached W3C Recommendation status on November 16, 1999. The specification documents for XPath 2.0, which is a subset of XQuery 1.0, were in late Working Draft stage at the time of this writing. XPath, both 1.0 and 2.0, is an essential part of the corresponding XSLT specification. This appendix focuses on XPath 1.0.
An XPath location path contains one or more location steps, separated by forward slashes (/
). Each location step has the following form:
axis-name::node-test[predicate]*
In plain English, this is an axis name, followed by two colons, a node test, and, finally, zero or more predicates each contained in square brackets. A predicate can contain literal values (for example, 4 or 'hello
'), operators (+, -, =, and so on), and other XPath expressions. XPath also defines a set of functions that can be used in predicates.
An XPath axis defines how to select a part of the model of an XML document, from the perspective of a starting point called the context node. The context node serves as the starting point for selecting the result of an XPath expression. The node test makes a selection from the nodes on the specified axis. In other words, a node test filters the nodes in the specified axis. By adding predicates, it is possible to filter any nodes already selected by selecting a subset of ...
Get Beginning XML, 4th Edition 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.