XML display -XSL style sheet (below)

zhaozj2021-02-11  188

XML display -XSL style sheet (below)

Beijing University of Posts and Telecommunications

XSL template

XSL describes the output format in the output template, which can be a variety of strings, tag symbols, node values, or some XSL syntax structures, such as conditional judgment, cyclic processing, and the like. In many applications, the value of the node is required in the output template. At this point, the element output node value can be used as needed, and the most direct way of use is , so The current node and the value of all its successive nodes can be output. And if you just want to output the value of the specified node, you can use the SELECT attribute to limit (the select property can be any legal path expression):

The first expression of the first expression is the element of the name in all subtites of the current node, and the second expression matching is the element named in all subsequent nodes in the current node. Note: There must be a template rule in the XSL style sheet to match the root elements.

After determining that the template rule matches the element, the template can be activated, which is done by element. It is combined with the element as the function call in the program: the former is the calling command, and the latter is a function body. Different types of templates are required for different elements. In order to activate the template rules in the style sheet, the element is used in the root element template rule, so that the entire style single file is taken effectively:

Use the element to indicate that all child nodes to be distinguished from the current node can be used in the SELECT attribute, and the work object can be qualified:

The first template described above matches the root element of the XML document, and applies template rules for all elements below the root node. Then, once the tag is encountered, insert a

tag as a blank paragraph, then apply template rules to elements and elements. Finally, the result of the conversion display is the 36-pound staff name and staff pay for the staff. XSL expansion rules

Path indicator

In addition to the "//" and "/" path indicators, as well as commands "*", there are several symbols to limit the matching object of the template:

● The current node indicator is ".";

● The parent node indicator is "..";

● The attribute indicator is "@".

The above "@" represents a matching of a attribute in the specified element, such as statement represents the property application template rule in the property of the element.

2. Filter match

In addition to the path indicator, it is possible to filter or sort the functional objects to further adjust the application effect. When filtered, it is generally based on child elements (or attributes):

● The child element exists: ie // EMPLOYEE [SALARY] exists, select all elements containing child elements;

● Child elements Value: Employee [Salary> 25000], select all elements containing sub-elements, and SALARY value is greater than 25,000;

● Attribute exists: 即 Employee [@ID] exists, select element containing attribute;

● Attribute value: 即 Employee [@ID = "1234"], select all elements of all attribute ID values ​​1234.

3. Other extension filtering

Other additional features of additional features are divided into: comparison operators, Boolean operators, and collection indexes.

The writing format and function of the comparison operator are as follows:

Operator function

$ EQ $ is equal to

$ NE $ 不

$ lt $ less than

$ Le $ less or equal to

$ GT $ greater than

$ GE $ greater than or equal to

It should be noted that the operator in the table is sensitive to the case when comparing characters. If you want to ignore the different meaning of case, add the prefix letter "i" in front of each operator, such as "$ Ieq ".

Boolean operator writing format and function description:

Operator function

$ AND $ logic

$ OR $ logic or

$ not $

The result of the filtration can be further filtered through a set index. For example, Employee [Salary] [2] is to select all elements that contain the child elements. In addition, XSL also provides a set index function for users to use: The index method represents the index number of the filter results, and the End method represents the last filtered result. How to use as follows:

Employee [index () $ lt $ 2]

EMPLOYEE [end ()]

The selection result of the first expression is the first and second sub-elements of the element, and the selection result of the second expression is the last sub-element of the element. In the default, the template rule to the element's matching order is scheduled according to the node appears in the front and rear order of the XML document. However, in a particular application, it may be necessary to adjust the original order, and the ORDER-BY attribute needs to be used. How to use as follows:

Order-by = "Number (Salary" />

The first example described above indicates that the letter should be arranged in order of the name, such as "Bob" should be ranked before "TOM", and the second example is sorted by the staff in accordance with the salary.

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

New Post(0)