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:

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.

   

back to top