HTML and CSS Reference
In-Depth Information
Plan
Ahead
Formatting and linking an XSL style sheet to an XML document.
XSL style sheets are used to transform an XML document into a more stylized document.
To create an XSL document, perform these tasks:
1. Determine the XML document elements that will be displayed and how you want them
to appear.
2. Determine the XSL elements:
a. Determine if the <template> element will use all or only some elements.
b. Determine the for-each elements.
c. Determine the style for each XSL value-of element and format with <span> tags and
inline styles.
d. Determine if sorting is required and which XML element to use as a sort key.
e. Determine any descriptive text that is needed.
3. Link the XSL style sheet to the XML document.
Formatting an XML Document Using
an XSL Style Sheet
XSL
XSL is three languages:
one to transform XML
(XSLT), one to define XML
parts or patterns (XPath),
and one to format objects
and define the XML
display (XSL). An XSL style
sheet assumes that the
associated XML document
uses a hierarchical
structure, which contains
a root element, child
elements, and any
optional attributes,
namespaces, processing
statements, or comments.
An XSL style sheet
cannot transform any
other type of document,
such as Word, PDF, or
PostScript files, into HTML
documents.
This section outlines the techniques needed to format the display of an XML document
using the Extensible Stylesheet Language (XSL) and to bind the XML document to the
XSL style sheet. Recall that the List link on the home page is an image that links to an
XML document that will display the products in description order. (Figure 12-1b on page
HTML 563). The output and display of this XML document are defined using an XSL
style sheet that sets each record to be displayed in a list, sorted in ascending order by the
<item-description> element.
To Open an XML Document and Save It with a New Name
Instead of the .xml file you started, you will continue with a file supplied in the Data
Files for Students that is similar but contains additional product items. The next steps
are to open that document, save it with a new name, and then create the XSL style sheet
to format and place the item listing in the desired order. See the inside back cover of this
topic for instructions on downloading the Data Files for Students, or contact your instructor
for information about accessing the required files.
The following steps open a text document, chapter12-1data.txt, and save it as
chapter12-1products_solution.xml.
1
Activate the Notepad++ window. Right-click the chapter12-1products.xml file tab, and
click Close on the shortcut menu.
2
With the USB drive plugged into your computer, click File on the menu bar, and then click
Open on the File menu.
3
If necessary, navigate to the Chapter12\ChapterFiles folder on the USB drive. Click All
types (*,*) in the Save as type drop-down list.
4
Double-click chapter12-1data.txt in the list of files.
5
Click File on the menu bar, and then click Save As on the File menu.
Search WWH ::




Custom Search