HTML and CSS Reference
In-Depth Information
association identifies the XML elements that should appear in the items list on the Web
page. Table 12-25 shows the general form of the for-each element.
The XSL for-each
The for-each element
allows a developer to
“loop” through a set of
XML data. The use of the
for-each selects every item
in a set of nodes. In the
event of multiple items,
the first value is used.
Table 12-25 General Form of the for-each Element
General form:
<xsl:for-each select="pattern">
The for-each element returns the associated child element's data identified by the select
attribute pattern. As the for-each cycles through the data, each of the child nodes contained in
the pattern name becomes the current node element or record.
<xsl:for-each select="products/item">
XSL style sheets allow for a more free-form, yet organized, display of data. To display
the items in order by item description, use the sort element as shown in Table 12-26.
The XSL sort Element
If the select attribute
is omitted, the XSLT
processor sorts on all the
elements as a string as the
sort key.
Table 12-26 General Form of the sort Element
General form:
<xsl:sort [select="value" lang="token" data-type="value" order="ascending|descending"
case-order="upper-irst|lower-irst"] />
The sort element has five optional attributes: select, lang, data-type, order, and case-order.
The select attribute value indicates on which element to sort; lang indicates the language
of the sort keys. The system default language is assumed. Data-type is used to indicate the
data type of the select value (alphabetic or numeric). In an alphabetic sort, numbers are sorted
alphabetically, meaning 100 comes before 99. Numeric data types sort numbers in their correct
numeric order. Order indicates ascending (default) or descending. Case-order indicates if
uppercase or lowercase order should be first.
<xsl:sort select="item-description" data-type="text" />
In conjunction with the for-each element, XSL uses the <xsl:text> tag to display
text on a page. Any text placed between the <xsl:text> and closing </xsl:text> tags
will display based on the formatting of any HTML tags. Recall that spaces in XML
documents are kept, unlike in HTML documents where special codes must be used to
insert a space.
To display any element values from the XML document, the XSL style sheet uses
the XSL value-of element to display each instance within the item list. Table 12-27 shows
the general form of the XSL value-of element.
The XSL value-of
The value-of element
transfers the value of the
designated XML tag (field)
to the output document.
Table 12-27 General Form of the value-of Element
General form:
<xsl:value-of select="pattern" />
The value-of element indicates that the page should display the value for the specified
element. The pattern value of the select attribute identifies the name of the specific element
used in the output.
<xsl:value-of select="item-description" />
To Add XSL Style Sheet Tags
Table 12-28 on the next page shows the code for the remainder of the XSL to sort the data by item-description
in ascending order and display the item-description, item-boh, and item-cost in a sentence format on the Web page.
Search WWH ::

Custom Search