XML technologies / XSLT / Introduction to XSLT 2.0 / XSLT and XPath – round two / Summary and exercises / Answers to the questions
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 2.)
Question 1: Which sequence does path expression beispiel[test] select?
a) All child nodes <test> of an <beispiel> element.
b) All elements <beispiel> with a child node <test>.
c) All elements <beispiel> with an attribute test.
b) is correct. The last location step’s node test determines the result set, here element nodes named <beispiel>. A predicate only restricts the set, here to <beispiel> elements with a child <test>.
Question 2: What does function fn:position() return?
a) The current node.
b) Its position in the document.
c) Its value as an integer.
d) Its position in a sequence.
d) is correct. The function always refers to the current sequence and returns the current item’s position as an integer, independently of document order. It never returns anything other than an integer.
Question 3: Which instruction also copies an element’s attributes to the result?
a) Instruction xsl:copy.
b) Instruction xsl:copy-of.
c) Instruction xsl:attribute.
d) Instruction xsl:attribute-set.
b) is correct. Instruction xsl:copy-of copies the entire selected branch with attributes and namespaces. By contrast, xsl:copy copies only the context node. Attribute nodes can be copied when they are context nodes, but not automatically with their parent.
Question 4: Which attribute of xsl:number determines the counted nodes?
a) The format attribute.
b) The value attribute.
c) The count attribute.
d) The level attribute.
c) is correct. Even for multilevel numbering, the element names are listed in attribute count. Their order is irrelevant because xsl:number uses the document hierarchy to map the format string. Supplying attribute value formats that value instead of counting.
Question 5: On which XPath axis does xsl:number count?
a) The Preceding axis.
b) The Preceding-Sibling axis.
c) The Following-Sibling axis.
d) The Following axis.
b) is correct. Counting always looks backward, moving up the context node’s Ancestor axis until finding a node matching attribute count, then counting its Preceding-Siblings. Attribute select selects another starting node, while attribute from further restricts the operation’s scope.
Question 6: Which functions construct their own sequence?
a) Function fn:count().
b) Function fn:last().
c) Function fn:sum().
d) Function fn:position().
a) and c) are correct. Functions fn:count() and fn:sum() take an XPath expression producing a sequence, which becomes their input. Functions fn:last() and fn:position() instead are context functions without arguments, referring to the existing sequence.
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