XSL introduction (1)

Source: Internet
Author: User
Tags xsl xsl file xslt
Document directory
  • XSL (1)
XSL (1)

Some people say that XSLIs it the replacement of CSS?

1. Introduction
XSL is a language that describes style sheets, including XSLT, XPath, and XML format objects.Three parts.
Unlike HTML, XML does not have predefined labels, so Browsers Do not know how to display XML documents, while XSL is used outside XML to show how to display.

2. XSLT
XSLT is a language that converts an XML document to another format. XML uses XSLT to convert the source XML tree to the result XML tree.

3. browser differences
Together with IE6, The MSXML parser fully supports javast1.0 and xpath1.0, and netscape6 does not fully support XSL (What about ns7 ?)

4. XSL style sheets
An XSL file is also an XML file, so the first line should also declare XML:

<? XML version = "1.0" encoding = "ISO-8859-1"?>

In the second line of the XSL Declaration, the following statement is completely consistent: <XSL: stylesheet version = "1.0"
Xmlns: XSL = "http://www.w3.org/1999/XSL/Transform">

And

<XSL: Transform version = "1.0"
Xmlns: XSL = "http://www.w3.org/1999/XSL/Transform">

When using the namespace above, you must have a description of version = "1.0.
ViewColumnExampleSub:XML file,XSL File,XML + XSL.

 

5. <XSL: Template> element
XSL style sheets are composed of templatesEach template is a set of rules..
The match attribute of the template to associate the template with the elements in XML. For example, match = "/" associates the template with the XML root.
  
6. <XSL: value-of> Elements
This element is used to obtain the selected XML node..
Select a node based on its select attribute. The select value is an XPATH expression. The XPath expression is very similar to the multi-level directory writing in * nix system. For example, "breakfast_menu/food.

7. <XSL: For-each> element
Complete the cyclic action in XSL. The select attribute is described in Section 6.
This element can be used for simple filtering, for example:

<XSL: For-each select = "catalog/CD [artist = 'Bob dylan']">

It can be used to find Bob Dylan's CD files. XSL defines four comparison operators: =,! =, & Lt, & GtAnd or can be used to connect the two comparisons.

 

8. <XSL: Sort> Elements
To sort the output, you only need to put it within <XSL: For-each> and use select to specify the comparison element.

9. <XSL: If> element
When the specified conditions are met, the <XSL: If> template will be used. The definition of the condition is indicated by its test attribute, and its operator is the same as 7.
Generally, <XSL: If> appears in <XSL: For-each>.

10. <XSL: Choose>, <XSL: When>, and <XSL: otherwise> Elements
These three conditions are combined to achieve multi-Condition Selection, similar to the case statement in C language. Example:

<XSL: Choose>
<XSL: When test = "Price & gt; 10">
... Some code...
</XSL: When>
<XSL: otherwise>
... Some code ....
</XSL: otherwise>
</XSL: Choose>

 

10. <XSL: Apply-templates> element
Use a template rule for the current element and its child elements, such as the delivery function in C, which implies the function of loop. Use the select attribute to specify the element. Match is used to determine what elements are sent from the template. From this point, the template is like an overloaded function in C ++.

11. XSL on the client
When we open an XML file that references XSL in a browser, the browser converts XML to XHTML before display.ConcealedAction.
This action can be explicitly completed using JavaScript on IE, provided that XML does not contain references to XSL. The Code is as follows:

<SCRIPT type = "text/JavaScript">
VaR xml = new activexobject ("Microsoft. xmldom ")
XML. async = false
XML. Load ("cdcatalog. xml ")
VaR XSL = new activexobject ("Microsoft. xmldom ")
XSL. async = false
XSL. Load ("cdcatalog. XSL ")
Document. Write (XML. transformnode (XSL ))
</SCRIPT>

12. XSL on the server side
For IIS, XML conversion can be easily implemented on the server side. As follows: <%
Set xml = server. Createobject ("Microsoft. xmldom ")
XML. async = false
XML. Load (server. mappath ("cdcatalog. xml "))
Set XSL = server. Createobject ("Microsoft. xmldom ")
XSL. async = false
XSL. Load (server. mappath ("cdcatalog. XSL "))
Response. Write (XML. transformnode (XSL ))
%>

  What about other types of servers?

 

The above is just the basic content, and advanced learning is behind it. :)
The main reason is that the elements are not comprehensive, and the XSL functions are not.
Http://www.w3schools.com/xsl/xsl_w3celementref.asp
Http://www.w3schools.com/xsl/xsl_functions.asp

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.