HTML and CSS Reference
In-Depth Information
6
If necessary, navigate to the Chapter12\ChapterFiles folder on UDISK (G:).
7
Type chapter12-1products_solution.xml in the File name text box and then click
the Save button.
Creating an XSL Style Sheet
As previously stated, an XML document can be formatted with CSS or XSL style
sheets. Most Web developers agree that formatting with CSS is impractical and prefer to
use XSL style sheets. An XSL style sheet performs two actions: it formats and transforms
XML documents. An XSL style sheet can transform an XML document by instructing
the browser or parser to output the XML document in a completely different form. XSL
takes the XML document, called a source , and produces completely different output,
called a result tree .
An XSL style sheet uses syntax similar to the syntax used for XML documents and
has the same hierarchical, treelike structure as other XML documents. Each of the style
sheet elements in an XSL style sheet must use the namespace prefix, xsl , to distinguish the
XSL elements from XML elements. To define the namespace, after the prolog statement,
the first element is the root element. The root element in an XSL style sheet is the
<xsl:stylesheet> or the <xsl:transform> tag, and must include a version. The general format
of these root elements is shown in Table 12-21. For a complete list of XSL style sheet
elements, see the XML Quick Reference in Appendix H.
The XSL stylesheet
Element
The xsl:stylesheet
or xsl:transform
element must have a
version number and
should be written as
follows: <xsl:stylesheet
version="1.0"
xmlns:xsl="http://
www.w3.org/1999/
XSL/Transform">
or <xsl:transform
version="1.0"
xmlns:xsl="http://
www.w3.org/1999/XSL/
Transform">. The version
number is required
because the namespace
code, xmlns:xsl="http://
www.w3.org/1999/XSL/
Transform", indicates the
use of the official W3C
specification.
Table 12-21 General Form of the stylesheet Element in an XSL Style Sheet
General form:
<xsl:stylesheet xmlns:preix="URL" language="language">
... (other stylesheet code)
</xsl:stylesheet>
or
<xsl:transform version="v.x" xmlns:preix="URL" language="language">
... (other stylesheet code)
</xsl:transform>
Comment:
The stylesheet (or transform ) element is the root element of an XSL style sheet. The prefix
defines the xml namespace (xmlns). The namespace allows duplicate names to be used in a
document. The URL indicates the official XSL specification as recommended by the W3C. The
language attribute is optional. The stylesheet or transform element must be closed at the end
of the document by the end tag, </xsl:stylesheet> or </xsl:transform>.
Examples:
(1) <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
(2) <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
The stylesheet or transform element establishes a namespace, so the remaining
elements, such as the template, can use names that will not be confused with other
elements. A template is an instruction that identifies the elements in a document that
should be transformed or converted and then specifies how the element should be
transformed. The browser refers to the template when displaying a particular element in
the XML document. The template is the most important part of the XSL style sheet, and
the XSL style sheet must include at least one template element. Table 12-22 shows the
general form of the template element.
Search WWH ::




Custom Search