Chapter 2 of the basic XSL tutorial

Source: Internet
Author: User
Tags xsl file
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:
    

    

    

    

    

      













      









                                                                             
TitleArtist


    

    

    

    

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:
    

    

    

    

    

    



















                                                            
TitleArtist
..


    

    

    

    

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:
    

    

    

    

    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.