This appendix contains suggested solutions to the exercises at the end of most of the chapters in this book.
This chapter introduced XPath 2.0.
Name some common XPath axes used to select element and attribute nodes.
Arguably the most commonly used axes are those that are used to select elements up and down the tree, probably in the following order. The
child:: axis is implicit in the majority of selections, with the
attribute:: axis coming in a close second.
Assume that the context is in an element node. Write the expression that selects the
xml:id attribute node for the element using the full and shortcut syntaxes (you can use any element name you like).
In this example I used the reference element at the root of the quick-reference documents.
<xsl:value-of select= "reference/@xml:id"/> <xsl:value-of select= "reference/attribute::xml:id"/>
After reviewing the string functions in XPath, create a simple XSLT stylesheet that you can use as a function test bed. Include several additional examples inside
<p> elements using the following code as a guide:
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform version="2.0"> <xsl:output method="xml" indent="yes" encoding="utf-8"/> <xsl:template match="/"> <output> <p> <xsl:value-of select="string-join(('my', 'string', 'join', string(4.00)), ...