XSLT is easy to get started
1.1 What is the English standard name of XSLT XSLT is Extensible Stylesheet Language Transformation. According to the W3C specification manual (http://www.w3.org/tr/xslt), the earliest design of XSLT is to help the XML document (Document) to convert to other documents. However, with the development, XSLT is not only used to convert XML to HTML or other text formats, and more comprehensive definitions should be: XSLT is a language for converting the XML document structure. 1.2 Why do we already know with XSLT, XML is a simple and standard approach to exchange raw data between computer programs. Its success is not that it is easily written and read, more importantly, it fundamentally solves information exchange between the application system. Because XML meets two basic needs: (1). Separate data and expression. Information on weather forecasts can be displayed on different devices, television, mobile phones or others. (2). Transfer data between different applications. E-commerce data exchange has increasing the need to make this demand increasingly urgent. In order to make the data easy to understand, we need to display the information or print out, such as turning data into an HTML file, a PDF file, even a sound; also, in order to make data suitable for different applications, we must There is an ability to convert a data format to another. For example, the demand format may be a text file, a SQL statement, an HTTP information, a certain order of data calls, etc. And XSLT is the language we used to implement this conversion function. Convert XML to HTML, which is currently the most important function of XSLT. 1.3 XSLT history Thought many other XML family members, XSLT drafted and developed by W3C. Its main development has been as follows:. Proposed by James CLARK in 1995; officially proposal in August 1997 is XSL;. In May 1998, the demand summary was completed by Norman Walsh; on August 18, 1998, issued; .1999 The XSL 1.0 recommended version was officially released on November 16. At present, XSLT is still in rapid development, and the draft XSLT1.1 can be seen on the W3C website (http://www.w3.org/tr/xslt11). 1.4 What is XPath XPath is an important part of XSLT, and we will explain its detailed grammar in Chapter 4. So what is XPATH? Let's take a look at the "family" relationship of the XSL series. As shown below:
XSL is divided into obvious two processes when converting XML documents, and the first conversion document structure; secondly formats the documentation. These two steps can be separated and processed separately, so XSL gradually split into XSLT (Structure Translation) and XSL-FO (Formatting Objects) in the development process, and XSL-FO's role Similar to the role of CSS in HTML. And we focus on discussing the first step in the first step, that is, XSLT. In addition, we already know that XML is a complete tree structure document when learning XML. In the conversion XML document, you may need to process some (node) data, so how to find and locate the information in the XML document, XPath is a language specifically used to find information in the XML document. XPath is affiliated with XSLT, so we usually mix the XSLT syntax and XPath syntax. Using a more good understanding: If the XML document is viewed as a database, XPath is a SQL query language; if the XML document is viewed as a DOS directory structure, XPath is a collection of CD, DIR and other directory operation commands. 1.5 XSLT and CSS comparison CSS can also format XML documents, then why do CSS still need XSLT? Because CSS can control the style of the output, such as color, font, size, etc., it has a serious limitations, that is: (1) CSS cannot reorder the elements in the document; (2) CSS cannot judge and control Which element is displayed, which is not displayed; (3) CSS cannot statistically calculate data in the element; in other words, CSS is only suitable for outputting a relatively fixed final document. The advantage of CSS is simple, consumes less system resources; while XSLT is powerful, but because the XML tree is required, it is more memory. Therefore, we often combine them, such as using the XSLT processing document in the server, controlling the CSS. Can reduce the response time. 1.6 XSLT and IE5 released in the XSLT draft shortly, Microsoft provided a preview version that supported XSL function in IE4, which officially supported XSLT when IE5.0 was released, but because IE5 released than XSLT1.0 standard time early, The XSTL feature supported in IE5.0 is slightly different from XSLT 1.0. (呵 ~~~ One of the main reasons for XML is to solve the problem of HTML over-dependent browser, now Microsoft wants to work newly.). The standards performed in Microsoft IE5.5 have been substantially similar to the XSLT1.0 of W3C. But a headache is that IE5.0 has released millions of sets, and the XSLT you use is likely to be executed correctly by the customer's browser. At present, XSLT 1.1 is still in development, W3C and related organizations have also got unified with Microsoft negotiation. Ha ha ~~ The story is still not ending. Note: The grammar mentioned herein is based on the standards of XSLT 1.0, without any "dialect" of Microsoft. 2.XSLT Example 2.1 How XSLT converts XML We play an interesting part, you play the plasticine, press the different molds to make a needed shape. If we assume that the XML data document is a big plasticine, XSLT is like a mold, and it is necessary to make a needed shape. We entered the XML original document, use XSL as a template, through the conversion engine, the final output required HTML document. The conversion engine is the process of "force one according to force" in the metaphor.
In specific applications, there are special software to implement this conversion process, named XML Processor. There is already a lot of Processor software (hereinafter referred to in detail below), and XML Processor has been embedded in IE5.5. 2.2 An instance Now let's take a simple XSLT actual application example to get some sense of understanding. Many web designers see the code similar to HTML will be relieved, the code is kind and familiar. Example 1: "Hello, World!" Hello World as the first tutorial is already a practice in the program language. We also follow this practice to see how to use XSLT to display "Hello World". Although this example doesn't have any practical use, please don't worry, there is more detailed example. Step 1: Create to enter the XML document Hello.xml. XML Version = "1.0" encoding = "ISO-8859-1"?> Download URL: http://www.wrox.com (4). Microsoft's MSXML3. Download URL: http://www.microsoft.com/xml Some netizens should ask, I want to see what the "Hello World" is doing in the browser? In Microsoft's IE5.5 embeds the MSXML3 interpreter, you can use IE5.5 to open the Hello.xml file, you can see the result. If you only see the XML tree, not a separate "Hello World" word, indicating that your browser does not have MSXML3 version. What should I do if I don't want to see it? Then use the old approach in our XML tutorial, use JS implementation. (This has exceeded the scope of this article, but in order to be more intuitive, we provide example code here.) The following is an implementation code that can be saved as hello.htm, Hello.xml, Hello .xsl is placed in the same directory. Finally, you can see the effect with IE5.0 or later.