The components of a XML tree structure are called "nodes". With the help of XPath, all nodes of a XML document can be selected and then processed with XSL. Basically, in XPath one can distinguish between seven different node types:
- Root node: The root node is not to be equated with the root element. In each XML document both of them appear exactly once, whereby the root node can be considered as virtual parent node of the root element.
- Element node
- Attribute node
- Text node
- Namespace node
- Processing instruction node
- Comment node
XPath uses axes in order to be able to navigate to any direction within the document structure. Eleven of the altogether thirteen different axes allow the navigation through all element nodes of a XML tree. They are named according to family relationships. Whereas the attribute and namespace axes access only certain node types (attribute and namespace nodes of an element).
The initial point of each search in XML documents is referred to as context node. In the following images graphically displaying the first eleven axes available in XPath, this context node is called SELF.
The self axis contains the context node itself.
The child axis contains the direct descendants of the context node.
With the descendant axis all descendants of the context node are addressed.
The descendant-or-self axis contains all descendants of the context node and the context node itself.
With the parent axis the parent element of the context node is addressed.
The ancestor axis contains all ancetors of the context node.
The ancestor-or-self axis covers all ancestors of the context node and the context node itself.
With the preceding axis all predecessors of the context node are addressed exclusively to its ancestors.
The following axis covers all followers of the context node exclusively to its descendants.
The preceding-sibling axis covers all nodes having the same parent element as the context node and coming before the context node in the document order.
The following-sibling axis covers all nodes having the same parent element as the context node and following after the context node in the document order.
Not only element nodes
Besides the element nodes already explained, there are also other node types in XML files. The addressing of these special node types will be demonstrated in the next examples. All examples and XPath expressions are applied to the "University.xml" file:
|Explanation:||By the text() node test, the text (which means the element value) |
of the node being addressed is selected.
|Explanation:||The comment node of the ARCHITECTURE element is |
selected with the comment() node test.
|Result:||<!-- The number may increase in 2013. -->|
|Node type:||All node types except for attributes|
|Explanation:||The node() node test selects all node types|
except for attributes.
|Result:||Selection of the philosophy nodes|
Also PI nodes (Processing Instructions) may be selected by the processing-instruction() node test.
|<< back||next >>|