Author: Hu Chaohui has been placed above example, we can analyze the syntax and the results of which are key to the following carefully:
First, it is noted that the XSL file itself is a XML file, so the same statement as the XSL file is the same as the XML file. W3C This XML standard mechanism defines a lot of tags (elements) for XSL, and the XSL file is a combination of these tags and HTML tags. In the XSL file, you must have the following line of code:
Here, XSL: Stylesheet is the root element of the XSL file, contains all typesetting styles in the root element, and the style sheet is combined by these typographic style; XMLns: XSL = "http://www.w3.org/tr / WD-XSL "This sentence is mainly used to indicate that the XSL style sheet is the XSL developed using W3C, and the set value is the URL address where the XSL specification is located.
In fact, here "http://www.w3.org/tr/wd-xsl" is a name space (Namespace), which we have already described time about XML Schema syntax. This is a standard name space. "Stylesheet", "Template", "for-Each", etc. are defined by this name space.
Of course, in XSL: Stylesheet, you can set other properties, and other properties are:
1. Default-Space: Decide if the blank in the XML file is retained, and only when the value is "default".
2. Indent-result: Decide whether to keep blank in the XSL file, the value is reserved when "Yes".
3. Language: Set the scripting language used in the XSL file.
Then, we see the following code in the code:
Here, it is actually a process of processing the XML document on the XML document, which determines from the root node (by match = / "," / "means a root node), and traverses the XML document, and according to specific The code takes out the relevant content from the XML document. Here is a more complex problem with the value of attribute Match. It is actually the meaning of removing a specific node collection from an XML document (XML document can be seen as a tree structure, which has a detailed introduction in the XML parser analysis). Here, we use several simple examples to illustrate the value of the property Match.
For example, one line of code:
The line of this line means telling the XSL parsing program. The node that needs to be processed is the content under the root node ("/" to represent the root node), in fact, the writing of the match value here is to comply with the language of XPath. About XPath We will perform a detailed introduction in the following chapters.
Take another example:
This line code must match the Item element under the ShoppingCart element. No matter which position under the XML document structure is in the XML document. For example, one of the XML documents is like this.
Then it matches the content is
And the following example:
Indicates all Item elements under this node under the root node of the XML document. In other words, if ShopPingCart is not directly under the root node, it does not meet this matching condition.
Look at an example:
This example shows that such a node is: a element Price with a Unit property, and the value of Unit must be "USD". For example, an XML code is like this.
Then it matches the content:
In fact, there are many symbols to represent match rules, and we will talk in detail in the XPath syntax. Now I know such a probably concept.
We use
Here: "Words"> is in
At the same time, we need to pay attention to the above code, there is a statement
What does it mean? It is actually equivalent to a process call in C . When the XSL parser executes the statement, it will find Xml: namespace prefix = xsl />
Watching as a process call, put
....... Xsl: template>
It seems that the implementation of the process helps us understand the XSL parser execution process. Here, Match = "Network Language Collection" can be understood as a parameter passed to the process, which indicates that the set range of the process implementation is the Node Collection Space ("Network Term Collection").
What do we need to sort the elements in the table? For example, in the above example, we need to sort in the name. Very simple, rewrite is as follows:
If we just want to take a few rows in the list? For example, we just want to take out the name "Dinosaur", see the code below:
Here is a new syntax for: