Appendix B. XPath Reference

This appendix contains reference information from the XPath specification. The XPath node types, axes, and operators are defined here. The datatypes used in XSLT stylesheets, including the result tree fragment type (technically defined in the XSLT specification, not in XPath), are defined here as well. This appendix concludes with a definition of the XPath context.

XPath Node Types

There are seven types of nodes in XPath. We’ll stick to the reference material here; for more information on the different node types, see our earlier discussion of the XPath data model.

The Root Node

The root node is the root of the tree. Unlike all other nodes, it does not have a parent. Its children are the element node for the document, along with any comments or processing instructions that appear outside the document element. The root node does not have an expanded name.

Element Nodes

Each element in the original XML document is represented by an element node. The expanded name of the element is its local name, combined with any namespace that is in effect for the element. You can access the different parts of the element name with the name(), local-name(), and namespace-uri() functions. Here is an element from an XML document:

<xyz:report xmlns:xyz="http://www.xyz.com/">

The values of the three functions for this element node are:

name()

xyz:report

local-name()

report

namespace-uri()

http://www.xyz.com/

Attribute Nodes

Attributes of elements in the XML document ...

Get XSLT 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.