This section describes how to use XSL to convert XML into HTML. The details of this example will be described in the next section. Starting from the XML document, start from the XML document that is going to be converted into HTML: the reference content is as follows :? Xmlversion = 1.0? CATALOGCD
XSL-conversion
This section describes how to use XSL to convert XML into HTML. The details of this example will be described in the next section.
Starting from the XML document
First, start with the XML document to be converted to HTML:
Reference content is as follows:
Empire Burlesque
Bob Dylan
USA
Columbia
10.90
1985
.
.
.
If Internet Explorer 5.0 or later is applied, you can view the results of the XML file.
Create an XSL style sheet document
Create an XSL style sheet using a conversion template:
Reference content is as follows:
If Internet Explorer 5.0 or later is applied, you can view the results of this XSL file.
Connect a style sheet to an XML document
Add an XSL style table reference to the XML document:
Reference content is as follows:
Empire Burlesque
Bob Dylan
USA
Columbia
10.90
1985
.
.
.
If there is a browser compatible with XSL, such as Internet Explorer 5.0 or later, XML can be converted to HTML. Click here to view the results.
XSL Template
XSL uses templates to describe how to output XML.
CSS application rules
If we have learned about CSS, we will know that CSS uses one or more rules to define the output of HTML elements, and uses a selector to associate the rules with an HTML element. For example, the p selector in the following CSS rules should use a font called arial to display
Element:
P {font-family: arial}
XSL application Template
XSL uses one or more templates to define how to output XML elements, and uses a matching attribute to associate the template with an XML element, you can also use the matching attribute to define a template for a complete branch of the XML document.
See the following XSL style sheet, which contains a template to output the xml cd directory in the previous section:
Reference content is as follows:
Since a style sheet itself is an XML document, the document begins with an xml declaration: . The xsl: stylesheet tag in the second row defines the beginning of the style sheet. The xsl: template tag in the third row defines the beginning of a template. Template Attribute match = "/" associates the template with the root (/) of the XML source document. The other part of the document includes the template. the last two rows define the end of the template and the end of the style sheet.
Use Internet Explorer 5 to view XML files, XSL files, and results.
Element
The results in the previous example are a bit disappointing because data is not copied from the XML document to the output. XSL Elements can be used to select XML elements in the input XSL conversion output stream:
Reference content is as follows: