XML technologies / XSLT / Introduction to XSLT 2.0 / XSLT and XPath – getting started / Summary and exercises / Answers to the questions
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 1.)
Question 1: Which node type is not a “Child” of its parent?
a) Text node
b) Attribute node
c) Comment node
d) Processing instruction node
e) Namespace node
b) and e) are correct. Attribute and namespace nodes are not children of their element. They lie outside document order and are not part of the normal document tree. XPath expressions can access these node types only through their special axes. All other nodes listed here lie on element axes.
Question 2: What is an element node’s “value”?
a) Text and element content
b) Attribute values and text content
c) Its own text and its child elements’ text
d) Only its immediate child text nodes
c) is correct. “Value” always means a node’s string value. For an element, this comprises all text nodes contained directly or indirectly in descendants, including whitespace nodes. These are concatenated in document order. Attribute values, comments and PI nodes are excluded.
Question 3: The document node is…
a) …the root element of the processed XML document.
b) …the root element of the XSLT stylesheet.
c) …a virtual node containing the processed XML document.
c) is correct. A document node is generally a nameless, parentless node containing a document. It is the root node, not the root element, in the source document tree. Transformations create document nodes, some serialized as documents, except temporary trees.
Question 4: Why is the XSL namespace URI important in xsl:stylesheet?
a) The processor retrieves instructions from this address.
b) It identifies XSLT elements as commands.
c) It does not matter, provided the prefix is xsl.
b) is correct. The XSL namespace URI identifies XSLT elements by qualified name. They must be bound through a prefix, essentially freely chosen, to the fixed URI string "http://www.w3.org/1999/XSL/Transform". No actual resource is sought at this address, and the prefix need not be xsl.
Question 5: Which XSLT instruction constructs a node sequence?
a) xsl:stylesheet
b) xsl:template
c) xsl:apply-templates
d) xsl:value-of
c) is correct. The instruction xsl:apply-templates constructs a node sequence from the context node, defined by its attribute select. Without attribute select, it contains all children of the context node. Since it is constructed only on the element axis, no attribute or namespace nodes are included.
Question 6: What starts XSLT processing?
a) A template matching the document node
b) The first template in document order
c) The highest-priority template
a) is correct. The first template matches the source document node, or is the corresponding default template, since this is the initial context node. The order of template rules in the stylesheet is irrelevant.
An exception is a named (!) template explicitly designated as the entry point, an initial template. In Saxon 9, specify a starting template with option -it:name_des_templates. No source document is needed in this case.
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