Concept
Outline
This article is divided into five chapters: the XSLT concept, the XSLT instance, the XSLT element syntax, the XPath syntax, and the XSLT resource.
The concept of 1.XSLT
1.1 What is XSLT
1.2 Why do you use XSLT
The history of 1.3 XSLT
1.4 What is XPath
1.5 XSLT and CSS comparisons
1.6 XSLT and IE5
The concept of 1.XSLT
Let's first clarify the concept that you may have heard of XSL (extensible Stylesheet Language), that XSL and the XSLT we're talking about are the same in the narrow sense, and that XSLT is more restrictive according to the standards of the world's standard, So we use the XSLT method uniformly in the article. The specific relationship between them will be described below.
1.1 What is XSLT
The English standard name for XSLT is extensible Stylesheet Language transformation. According to the specifications of the HTTP://WWW.W3.ORG/TR/XSLT, the first design XSLT was designed to help convert XML documents (document) to other documents. But with development, XSLT has not only been used to convert XML to HTML or other text formats, but a more comprehensive definition should be:
XSLT is a language used to transform the structure of XML documents.
1.2 Why do you use XSLT
As we already know, XML is a simple and standard way of exchanging raw data between computer programs. Its success does not lie in its easy to be written and read by people, and more importantly, it fundamentally solves the information exchange between application systems. Because XML meets two basic requirements:
(1). Separating the data from the form of expression. Like the weather information can be displayed on different devices, TV, cell phone or other.
(2). Transmission of data between different applications. The growing demand for E-commerce data exchange has made this increasingly urgent.
In order to make the data easy for people to read and understand, we need to display or print the information, such as turning the data into an HTML file, a PDF file, or even a sound; Similarly, in order for the data to fit into different applications, we must have the ability to convert one data format to another data format, For example, the requirement format may be a text file, an SQL statement, an HTTP message, a certain sequence of data calls, and so on. And XSLT is the language we use to implement this conversion function. converting XML to HTML is the main function of XSLT at the moment.
The history of 1.3 XSLT
Like many other XML family members, XSLT was drafted and developed by the consortium. Its main development process is as follows:
.1995 proposed by James Clark;
. The August 1997 official proposal was XSL;
. A demand summary was completed by Norman Walsh in May 1998;
. August 18, 1998 the release of the XSL draft;
. November 16, 1999 the official release of the XSL 1.0 recommended version.
Currently, XSLT is still evolving rapidly, and XSLT1.1 's draft is already visible on the Web site (http://www.w3.org/TR/xslt11).
1.4 What is XPath
XPath is an important part of XSLT, and we will explain its detailed syntax in the fourth chapter. So what is XPath? Let's first take a look at the "family" relationships in the XSL series. The following figure:
XSL divides the XML document into two distinct processes, the first to transform the document structure, and then the document to format the output. These two steps can be separated and handled separately, so the XSL gradually splits into XSLT (structural transformation) and XSL-FO (Formatting objects) (formatted output) in two branch languages, where XSL-FO functions like CSS in HTML. And what we're talking about here is the first step of the transformation process, which is XSLT.
In addition, when learning XML, we already know that XML is a complete tree structure document. To find and locate information in an XML document, you may need to work with some of these (node) data when converting an XML document, and XPath is a language specifically used to look up information in an XML document. XPath is subordinate to XSLT, so we usually mix XSLT syntax with XPath syntax.
A better understanding of the explanation is that if you think of an XML document as a database, XPath is the SQL query language; If you think of XML documents as DOS directory structures, XPath is a collection of directory operations commands such as Cd,dir.
1.5 XSLT and CSS comparisons
CSS can also format XML documents, so why do you need XSLT when you have CSS? Because CSS is a good way to control the output of the style, such as color, font, size, etc., but it has serious limitations, is:
(1) CSS cannot reorder elements in a document;
(2) CSS can not judge and control which element is displayed, which is not displayed;
(3) CSS can not be statistical calculation of the data elements;
In other words, CSS is only suitable for the output of a more fixed final document. The advantages of CSS are simplicity, consuming less system resources; While XSLT is powerful, it consumes more memory because it is indexed to the XML tree.
Therefore, we often combine them, such as using XSLT to process documents on the server side, and using CSS to control the display at the client. can reduce response time.
1.6 XSLT and IE5
Shortly after the release of the XSLT draft, Microsoft provided a preview version of the XSL feature in IE4 to support XSLT when IE5.0 was released, but because IE5 was released earlier than the XSLT1.0 standard Time, IE5.0 features and XSLT supported in Xstl 1.0 slightly different. (hehe ~~xml Implementation of one of the main reasons is to solve the problem of HTML over-reliance on browsers, and now Microsoft wants to be unconventional? )。 Fortunately, the standards implemented in Microsoft's IE5.5 have been basically similar to the XSLT1.0 of the consortium. But the headache is that IE5.0 has released millions of sets, and the XSLT you use may well not be properly executed by the client's browser. XSLT 1.1 is still evolving, and the consortium and its organizations are also negotiating with Microsoft to achieve unification. Oh ~ ~ The story is far from over.
Note: The syntax mentioned in this article is based on the XSLT 1.0 standard and does not have any "dialect" from Microsoft.