XML technologies / XSLT / Introduction to XSLT 2.0 / XSLT and XPath – getting started / The XML document as a tree / Node kinds in the document tree

(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 1.)

The document tree in figure Parent-child relationships in a tree diagram has a peculiarity: its root is a node, shown as an oval, with no counterpart in the XML document. Contrary to what one might think, it does not represent the XML declaration!

Informally, this node stands for the document itself, containing or encapsulating it in full. It is therefore called the document node (document node). Processing always begins at this node, not at the subordinate root element. (Note: The rather abstract need for something outside the document becomes clearer if a “document” need not have exactly one root element. XSLT 2.0 interprets “document” quite broadly.)

Immediately below the document node, as its child, is the XML document’s root element <a>. A node representing an element is called an element node. Its content can include other element nodes and other kinds of nodes.

In this simple example, elements <c> and <d> contain only text, appearing as two text nodes in the tree. Comments appear as comment nodes and processing instructions as PI nodes.

Usually, attributes and namespaces are not shown in the tree, but remain accessible to XPath and have corresponding node kinds.

Reason: Attribute and namespace nodes are not children
Attribute and namespace nodes are absent because the tree follows a strict parent-child structure, and these nodes are not children of their associated elements. An attribute is in the start tag, not inside the element container.

The prolog’s XML declaration is not a node either. (Note: Despite its appearance, the XML declaration is not a processing instruction, so treating it differently is consistent.) Unlike attribute values and namespaces, it is inaccessible to XPath. Fortunately, it need not concern us. Only the XML parser uses it, among other things to determine the document’s character encoding.

XPath distinguishes seven node kinds according to the kinds of information units in XML documents. Each has individual properties and is handled differently in XSLT:

Some of these node types are examined more closely on the following pages.

   

back to top