This section looks at how to create an HTML list from an XML source document.
The XML source document contains information about a series of reports produced for XMML.com. In this HTML Web page, you will choose to display only reports for which the year of the report is 2002. Listing 10.5 shows the source XML document.
Listing 10.6 shows the XSLT stylesheet that selects for display reports dated 2002 and displays the title, year, and author name for each such report.
The preceding stylesheet bears many similarities to those you saw earlier in this chapter.
Notice the xsl:apply-templates element in the template that matches the root node. It is nested between the start and end tags of a ul element. So, the xsl:apply-templates element is used to create the content of the unordered list. The value of its select attribute is //Report[@year='2002']. The pair of forward slash characters (//) is abbreviated syntax for the descendant-or-self axis. Essentially, //Report means to select any Report element node in the document. The predicate [@year='2002'] filters that node-set so that it includes only Report element nodes that possess a year attribute whose value is 2002.
The XSLT template that matches the nodes in that node-set is then processed. The xsl:template element with the match attribute whose value is Report is instantiated. A list item element, li, is created. The xsl:value-of element is used three times:
<xsl:value-of select="Title" />(<xsl:value-of select="@year"/>):<xsl:text> </xsl:text> <xsl:value-of select="Author" />
First, the text content of the Title element is obtained, followed by the value of the year attribute of the Report element in parentheses. The third xsl:value-of element selects the text content of the Author element node for the report.
The xsl:text element is used to insert whitespace—in this case, a single space character—between the colon character and the author’s name. Using the xsl:text element to output whitespace ensures that it is preserved in the output document.
The output of the transformation is shown in Listing 10.7.