HTML and CSS Reference
In-Depth Information
Table 12-28 Code for Adding the for-each, sort, text, and value-of XSL Style Sheet Tags
Line
Code
10
<xsl:for-each select="products/item">
11
<xsl:sort select="item-description" data-type="text" />
12
<p style="margin-left:15%">
13
<span style="font-weight:bold; color:#7f0000">
14
<xsl:value-of select="item-description" />
15
</span>
16
<xsl:text> There are </xsl:text>
17
<span style="text-decoration:underline; font-weight:bold">
18
<xsl:value-of select="item-boh" />
19
</span>
20
<xsl:text> in stock and the cost is $</xsl:text>
21
<span style="font-family:arial, helvetica, sans-serif">
22
<xsl:value-of select="item-cost" />.
23
</span>
24
</p>
25
</xsl:for-each>
26
<p style="font-family:helvetica,arial; font-weight:bold">
<a href="chapter12-1home_solution.html">Home</a></p>
27
</xsl:template>
28
</xsl:transform>
Line 10 is the <for-each> tag that cycles through the XML file displaying each individual instance. Line 11
is the <sort> tag that directs the elements to be displayed in sorted order on the description using the <item-
description> element. The paragraph <p> tag on line 12 displays each record on a separate line, indented by
15 percent of window width from the left margin. Line 13 is a <span> tag with an embedded style sheet used to set
the font-weight to bold and the color to #7f0000. Line 14 uses the value-of select attribute to display the value for
the item-description element. Line 15 closes the <span> tag started on line 13, so the next text displayed does not
use the same style.
Line 16 uses the text attribute to insert the text “There are” between the item-desciption and the item-boh value
displayed by line 18. The inline style in line 17 displays the item-boh (number in stock) bold and underlined. Line 20
inserts the text “in stock and the cost is $” and the <span> tag on line 21 uses an embedded style sheet to set the font of
the item-cost, which is displayed with the <value-of> tag in line 22. Line 23 closes the <span>.
Line 24 closes the <p> tag on line 12. Line 25 closes the for-each element. Line 26 is a <p> tag with an embedded
style followed by an <a href> tag to create a link back to the home page. Line 27 closes the <xsl:template> tag on line 3.
Line 28 closes the <xsl:transform> tag on line 2, which began the XSL markup tag elements.
The following step enters the remaining code to complete the XSL style sheet.
Search WWH ::




Custom Search