
296
❘
CHAPTER 10 WEB PARTS AND XSLT
Notice that the for-each element is using an XPath expression for the select attribute. In this
expression (
quiz/question), the parser is going to take all question nodes that are children of the
quiz node. Knowing the format of the XML document being parsed, you could have just as easily
used
//question for this attribute, as follows:
<xsl:for-each select=”//question”>
This would have selected all question nodes, regardless of where they reside.
You will also notice another XSL element has been used in this example:
value-of. This element,
as the name implies, displays the value of the node selected by the XPath expression in the
select
attribute. So, with the XPath expression of simply
displayQuestion, the value-of element will
just show the value of the
displayQuestion node in the question element.
The last thing that needs to be done is iterate through the answers and display them as radio but-
tons. To do this, add the bolded text in the following code:
<xsl:stylesheet version=”1.0” xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>
<xsl:template match=”/”>
<html>
<body>
<h1>Easiest SharePoint Quiz Ever!</h1>
<ol>
<xsl:for-each select=”quiz/question”>
<li>
<strong>
<xsl:value-of select=”displayQuestion”/>
</strong>
<br/>
<xsl:for-each select=”answers/answer”>
<span style=”font-style: italic;”>
<input type=”radio”>
<xsl:attribute name=”name”>