XSL syntax introduction

xiaoxiao2021-03-06  95

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. 3333 Dragon Sword 4444 Part of the hook

Then it matches the content is 3333 Dragon Sword 4444 Part of the hook

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.

USD 100 RMB 300

Then it matches the content:

USD 100

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 This statement has found some node collection, we will find the value of a specific element or element property from this collection, then what statement is adopted? That is to use XSL: Value-of select = "" "" "" "" "" "" "" "" "" "" "" For example, in the example below This line is the content representing the name elements in the XML document. There may be multiple name elements in the specified collection. If we need to list them, you need to use statements xsl: for-each select = "", note that the concept of a range of scope is also That is to say xsl: for-each select = "" This statement is executed in a specified set space. Such as the following example in the above example

Here: "Words"> is in The specified collection space is looking for elements "words".

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 The code started, so in the example program above, the following code can be regarded as the implementation of the process.

Watching as a process call, put

.......

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:

, " " is arranged in descending order; "-" means being arranged in ascending order. "Order-by" is a keyword in the XSL syntax.

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:

It is represented if" [name = 'dinosaur'] "true (TRUE) If you do the statements in this paragraph, if you do false, you will not be executed. It is basically the same as the concept of the IF statement in C .

In front of us with is the value of an element, but what should we do to take out the value of an element for an attribute? Using the following form:

For example, a paragraph XML code is like this:

well-known writers plus famous critics Wang Hao's place

We can get the value "www.wangshuo.com" with .

The above includes most basic grammar of XSL, more detailed and complete introduction, you need to see the latest documentation related to W3C, which can be found under www.w3c.org/tr.

According to the above analysis, we can see that the XSL actually uses a conversion idea. It eventually converts the XML document to another document that can be used for output, and the CSS does not have any conversion action, not in the whole process Any new code is generated. In addition, 90% of the style in XSL specify that there is definition in CSS, but still have some effects that CSS cannot be described, and XSL must be used. These functions include the replacement of the text. According to the text content decision display, the document content sorting, etc. is unique to XSL. Furthermore, XSL follows the syntax of XML, while CSS's grammatical self-contained system.

转载请注明原文地址:https://www.9cbs.com/read-123055.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.036, SQL: 9