HTML and CSS Reference
In-Depth Information
The XSL template
Element
The XSL template
element associates each
output with an input.
The match="/" attribute
defines the entire
document.
Table 12-22 General Form of the template Element
General form:
<xsl:template match="pattern" language="language">
... (other stylesheet code)
</xsl:template>
Comment:
The pattern indicates the XML element or node. A pattern of "/" indicates that the entire
document will be displayed. The template element needs an end element.
Example:
<xsl:template match="/">
... (other stylesheet code)
</xsl:template>
To Start Creating an XSL Style Sheet
This XSL style sheet will display the items in order by item description, using the <item-description>
tag element in the XML file. Table 12-23 shows the code for the processing instruction, an XML declaration, a
stylesheet element, and a template element in an XSL style sheet.
Table 12-23 Code for Creating an XSL Style Sheet
Line
Code
1
<?xml version=”1.0” encoding=”utf-8” standalone=”yes” ?>
2
<xsl:transform version=”1.0” xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>
3
<xsl:template match=”/”>
Line 1 is the XML declaration that identifies this as an XML document using XML version 1.0. Line 2 is the
XSL stylesheet element used to define the namespace, xsl, for the remaining elements. Line 3 defines the template
pattern, using a “/” to indicate that the template applies to the entire XML document. The following step begins
creating an XSL style sheet.
1
If necessary, activate
the Notepad++
window.
saved filename
in tab
Click File on the
style sheet transform
element to define
namespace
menu bar, and
then New to start
a new Notepad++
document.
"/" indicates
template applies
to all elements in
document
start of template
element
With your USB drive
plugged into your
computer, click File on the
menu bar, and then click
Save As. If necessary, navigate to the Chapter12\ChapterFiles folder.
Figure 12-24
chapter12-1products_solution.xsl in the File name text box and then click the Save button.
Type
Enter the code shown in Table 12-23 to start the XSL style sheet, and then press the
e n t e r key once after line 3 (Figure 12-24).
What happens if more than one XSL style sheet is linked to an XML document?
If more than one XSL style sheet is linked to an XML document, the first XSL style sheet the browser reads is used and
the others are ignored.
Can an XSL style sheet and Cascading Style Sheet both be linked to an XML document?
If an XSL style sheet and a Cascading Style Sheet are both linked to an XML document, the XSL style sheet is used and
the Cascading Style Sheet is ignored.
 
Search WWH ::




Custom Search