http://blog.9cbs.net/airhand/archive/2004/08/26/85447.aspx
Easy Start XSLT first chapter: XSLT concepts of: Introduction Acha
Hello everyone, from today we will learn another language XSLT, XSLT similar to the CSS in HTML, but more powerful than CSS functions. The premise of learning XSLT is that you have some understanding of XML, if you have not learned XML, you can click here (http://www.technic.com.cn/columns/xml_1.shtml) to see a previous article Article "XML Easy Start Handbook". XSLT can be said to be a program language, but it is not a common program language, even more simple than JS, so you don't have to worry about learning difficulties. Ajie will still stand in the perspective of ordinary designers, introduce XSLT from the shallow into the language. Ok, let's explore the secret of XSLT!
Disclaimer: Because the standard of XSLT is constantly developing, the grammar is also expanding, the knowledge we have learned below is based on the XSLT 1.0 released on November 16, 1999, so it may be incomplete, the latest information, please W3C website (http://www.w3.org/tr/xslt).
outline
This article is divided into five major chapters: XSLT concept, XSLT instance, XSLT element syntax, XPath's grammar, XSLT resources.
1.xslt concept
1.1 What is XSLT
1.2 Why use XSLT
1.3 XSLT history
1.4 What is XPath
1.5 Comparison of XSLT and CSS
1.6 XSLT and IE5
1.xslt concept
We first clarify a concept, you may have heard that XSL (Extensible Stylesheet Language), XSL and XSLT we say here are the same, and according to W3C standard, XSLT is more strict, so we are The name of XSLT is unified in the article. The specific relationship between them will be described below.
1.1 What is XSLT
The English standard name of 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. But as developing, XSLT is not only used to convert XML to HTML or other text formats, and more comprehensive definitions should be:
XSLT is a language used to convert an XML document structure.
1.2 Why use XSLT
We already know that XML is a simple and standard way 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 satisfies 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
Think about many other XML family members, XSLT drafted and developed by W3C. Its main development history is as follows:
1995 was proposed by James Clark;
In August 1997 official proposal is XSL;
Summary of demand for Norman Walsh in May 1998;
Draft XSL draft, August 18, 1998;
The XSL 1.0 recommended version was officially released on November 16, 1999.
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 Comparison of XSLT and CSS
CSS can also format XML documents, then why do CSS need XSLT? Because CSS is capable of controlling the style, such as color, font, size, but it has a serious limitations, that is:
(1) CSS cannot reorder the elements in the document;
(2) CSS cannot determine and control which element is displayed, which is not displayed;
(3) CSS cannot statistically calculate the data in the element;
In other words, CSS is only suitable for outputting a 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
Soon after the draft of XSLT, Microsoft provided a preview version of the XSL function in IE4. When IE5.0 is released, I officially fully support XSLT, but because IE5 released than XSLT1.0 standard time, therefore in IE5.0 The XSTL functionality supported in the medium 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. Chapter XSLT Getting started is easy: Example of XSLT: Example of Acha 2.XSLT
2.1 How XSLT converts XML
2.2 an instance
2.3 Process Analysis
2.4 Use of XSLT
2.1 How XSLT converts XML
We play a fun, you play the plasticine, press the different molds to make the shape of the need. 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.
Specifically look at the following procedure:
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 look at a simple XSLT actual application example and 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"?>
This is a very simple XML document that contains only a node XML tree. Step 2: Establish a XSLT document Hello.xsl. Tip: The default XSLT file has the name of .xsl.
XML Version = "1.0" encoding = "ISO-8859-1"?> XML Version = "1.0" encoding = "ISO-8859-1"?> Xml-stylesheet type = "text / xsl" href = "hello.xsl"?> OK, all the code has been completed by this step, followed by using an XSLT processor (XML processor) to perform Hello.xml, you can see the result of "Hello World". The popular processor software has the following: (1) .james Clark XT. Download Website: http://www.jclark.com/xml/xt.html (2) XML for Java package named LotusxSL. Download Website: www.alphaworks.ibm.com/tech/xml4j (3) .saxon. 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 effect of "Hello World" is 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.