XML technologies / XSLT / Introduction to XSLT 2.0 / XSLT and XPath – getting started / Structure controls processing / Structure-driven processing flow
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 1.)
Processing is now clear. First the document-node rule activates, constructing a sequence containing only root element <adressen>.
The context is therefore the root element. No rule exists for this element, so the default element rule constructs a sequence of the children of <adressen>: the eleven element nodes <adresse>. Also selected are the whitespace nodes before, between and after the elements, making 23 nodes in total. The default text-node rule also processes whitespace nodes, which is why they reach the result document.
Rules were also “forgotten” for other elements. Processing <vorname> and <nachname> again uses the default element rule.
No specific sequence was forced, yet no tree nodes are skipped. Processing follows a simple iteration:
Rule 1:
If there is no current node, start at the input document’s document node.
This occurs only once, at the start. Thereafter, a current node is always available for processing.Rule 2:
If the current node has children, create a sequence of them and process it in order.
This applies to a document node or a nonempty element node.Rule 3:
If it has no children, next make the following node in the current sequence the current node.
This occurs among the children of<adressen>. The first node is whitespace: it is copied, then the next node, an element<adresse>, is processed.Rule 4:
At a sequence’s last node, return to the previous sequence’s last current node and process its following node.
This happens at several levels. When processing a node<adresse>, its children’s sequence and their children’s sequences are processed before focus returns and the next node, here whitespace, is handled. Eventually context returns to the document node and processing ends.
Attribute nodes remain excluded
This works well for elements and text, but automatically constructed sequences never contain attribute nodes. Those require an explicit sequence on the attribute axis.
The default template for attributes alone does not help, nor does the default value of attribute select on xsl:apply-templates. Node test node() in the form
<xsl:apply-templates select="node()"/>would theoretically match attributes too, but none are on the child axis being examined, since node() abbreviates child::node().
To process every child and attribute of an element without exception, use this expression while the element is the current node:
<xsl:apply-templates select="node() | @*"/>The alternative expressions’ order is again irrelevant, but attributes always come first in the resulting sequence. Usually attributes are selected individually rather than this broadly, using xsl:value-of as in the default template. The next chapter also uses attribute values or presence to define filter criteria.
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from “XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn