Author: Hu Chaohui has been placed above example, we can carefully analyze the results of the following syntax and the key to them: first of all be noted that, XSL file itself is an XML file, so in the beginning of the XSL document, as there The same statement 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, In the root element, all typesetting styles are included, and the style sheet is combined by these typesetting styles; XMLns: XSL = "http://www.w3.org/tr/wd-xsl" This sentence is mainly used to indicate the 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: ......... xsl: template> This is actually a process of processing the XSL parser on the XML document, It determines from the root node (by match = / "," / "means a root node), and the XML document is traversed, and the relevant content is removed from the XML document according to the specific code. 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, the following line code: This line of code means telling the XSL parser, the node that needs to be processed is the content under the root node ("/" to represent the root node), in fact The writing of match values is to comply with XPath. About XPath We will perform a detailed introduction in the following chapters.
An example is given: This line of 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 itemno> Dragon Sword itemname> item> 4444 Part of the hook itemname> Item> shoppingcart> Then it matches the content is 3333 Dragon Sword itemname> item> 4444 4444 Seed from the hook itemname> item> and below: Indicates all Item elements under the node that matches the node of the XML document root node. In other words, if ShopPingCart is not directly under the root node, it does not meet this matching condition. Look at an example:
USD unit> 100 amount> price> RMB unit> 300 amount> price> then it matches The content is: USD unit> 100 amount> price> In fact, there are many various symbols to represent match rules, we will 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. For example, the following example is the is in The specified set space is looking for elements "words". At the same time, we need to pay attention to the above code, there is a statement It means, it is actually equivalent to a process call in C , When the XSL parser performs the statement, it will find the code in the code in the code in the code, the code in the top of the previous example, so the example of the above example In the following code, it can be seen as the implementation of the process. It is a process call to see the ...... xsl: template> to see the implementation of the process, help us to 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, rewritten as the following form:
Td>
td> xsl: if> xsl: for-energy> table> xsl: template> It represents if "[Name = 'Dinosaur']" True, the statement in this section is executed, if false, does not execute. 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 writer plus famous commentator Wang Hao Mr.'s place Wang Hao> 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.