Introduction to other elements of the template
Element name and description
Xsl: apply-imports
Call the imported external template, which can be applied as a template of some documents
Xsl: apply-templates
Application Template: click "" to determine the template to be applied. When multiple templates meet the requirements, select a template based on the priority. When the priority is the same, apply the last Style
Xsl: attribute
Define attribute nodes for element output. The attribute key is "name" and the attribute name is defined. "namespace" declares the namespace.
Xsl: attribute-set
Define a group of attribute nodes. The keyword "name" defines the group end name, and "use-attribute-sets" declares the matching attribute to each node.
Xsl: call-template
Call the template specified by call-template
Xsl: choose
Call template based on conditions
Xsl: comment
Add comments to the output
Xsl: copy
Copy current node to output
Xsl: copy-
Copy all the subtree of the current node, such as the attribute node and the slave node, and wait until the output
Xsl: decimal_format
Defines the decimal format output by the formatting numeric function, such as decimal-separator and infinity.
Xsl: element
Create an element in the output
Xsl: fallback
When the XML analyzer does not support the current XML version, this element is called to determine whether it can be processed normally. If not, the default method is used for processing and an error message is output.
Xsl: for-each
The cyclic call template matches each node.
Xsl: if
Template calls in simple conditions
Xsl: import
The imported style sheet can only be used as the byte points of "xsl: stylesheet" and "xsl: transfor. The imported style sheet has the highest priority (higher than the style sheet specified by the current style sheet and "xsl: include)
Xsl: include
Import other style sheets in a way similar to "xsl: import"
Xsl: key
Define keywords, and then use the key () function to make keyword judgment. It is mainly used in XPath.
Xsl: message
Send text message to message buffer or message dialog box
Xsl: namespace-alias
Change the current namespace
Xsl: number
Insert a formatted number into the result tree.
Xsl: otherwise
Conditional call Template
Xsl: output
Specify application options for the serialized result tree
Xsl: param
Specify parameters for xsl: stylesheet or xsl: template
Xsl: preserve-space
Leave spaces in the document
Xsl: processing-instruction
Add processing commands to the output
Msxsl: script
Define global variables and functions in the extension script
Xsl: sort
Sorting Node
Xsl: strip-space
Space for merging documents
Xsl: stylesheet
Specify a style sheet
Xsl: template
Template
Xsl: text
Output text
Xsl: transform
Equivalent to xsl: template
Xsl: value-
Add text values to selected nodes
Xsl: variable
Declare variables in an expression
Xsl: when
Select Template
Xsl: with-param
Undo template parameters
In addition to the circular matching template method similar to function calls mentioned above, XSLT also has other elements similar to our common programming languages. The following describes how to call a template matching method under simple conditions (only matching and mismatched conditions) and multiple selection conditions.
The template calling format is as follows:
<Xsl: if text = "Boolean expression">
......
</Xsl: if>
When the value of a Boolean expression is true, the content represented by the ellipsis is executed. Otherwise, the content is skipped. This can only be judged in two cases. When you select a matching template for multiple cases, use the elements <xsl: choose>, <xsl: otherwise>, and <xsl: when> in the following format:
<Xsl: template match = "">
<Xsl: choose>
<Xsl: when test = "Boolean expression A">
// Code segment 1
</Xsl: when>
<Xsl: when test = "Boolean expression B">
// Code segment 2
</Xsl: when>
<Xsl: otherwise>
// Code segment 3
</Xsl: otherwise>
</Xsl: choose>
<Xsl: apply-templates/>
</Xsl: template>
Just like A programming language: When Boolean expression A is true, code segment 1 is compiled and executed. When expression B is true, code segment 2 is executed. In other cases, code segment 3 is executed. We can use these two methods to selectively present some XML documents.
The following examples show how to use the elements in the table to complete XML Conversion.
The creation element is written as follows:
<Xsl: element name = "TITLE">
This is a test.
</Xsl: element>
The elements are as follows:
<TITLE> This is a test. </TITLE>
The element "xsl-attribute" must be used to create an attribute ". For example, the attribute "ID" created for the element "TITLE" is written as follows:
<TITLE>
<Xsl: attribute name = "ID">
Title1
</Xsl: attribute>
This is a test.
</TITLE>
The attributes created for the element "TITLE" are:
<Title id = "title1"> This is a test. </TITLE>
We can also add comments to the document to increase the readability of the Code:
<Xsl: comment> Create a title. </xsl: comment>
After conversion, the resulting comments are as follows:
<! -- Create a title -->
In the previous table, we talked about using "copy" and "copy-of" to copy nodes, for example:
<? Xml version = "1.0"?>
<A id = "001">
<B> comment </B>
<C> text </C>
</A>
We use a style sheet to copy nodes:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/TR/WD-xsl">
<Xsl: template match = "A">
<DIV>
<Xsl: copy-of select = "."/>
</DIV>
<DIV>
<Xsl: copy/>
</DIV>
</Xsl: template>
</Xsl: stylesheet>
The conversion result is:
<DIV>
<A id = "001"> <B> comment </B> <C> text </C>
</DIV>
<DIV>
<A/>
</DIV>
The result is that "xsl: copy-of" copies all content of the current node, including the node itself, attributes, and sub-elements. While "xsl: copy" only copies the current node itself.
XSLT can convert XML documents into multiple types of documents. We use the element "xsl: output" to specify the types of output documents.
<Xsl: output method = "html">
The output document type is html document. The default output document type is XML unless the output document type is specified. If you use the
The "xsl: sort" element can sort nodes, for example, by size:
<Xsl: sort case-order = "lower-first" select = "@ ID">
<Xsl: sort case-order = "upper-first" select = "@ ID">
In this case, sort by the keyword ID according to the method specified by "case-order. When "case-order" specifies "lower-first", the keyword ID value is lower-case first, and "case-order" specifies "upper-first, the keyword ID value is capitalized before.
If it is written:
<Xsl: sort order = "ascending" select = "@ ID">
Then, the sort is sorted in ascending order based on the letters of the keywords. If the value of "order" is changed to "descending", the key words are sorted in descending order. Here, the keyword is still the value of the "ID" attribute.
The "xsl: sort" element can also be sorted by numbers. There are two methods:
<Xsl: sort data-type = "text" select = "@ ID">
<Xsl: sort data-type = "number" select = "@ ID">
There is a set of ID attribute values. The result obtained using the previous method is. The result obtained by using the second method is: 34,156. The two methods are different.
"Xsl: sort" can also be sorted by custom keywords. For example: <xsl: for-each select = "A" order-by = "B">
Specify the matching node "A" and sort the content of A according to the keyword B.
Next we will introduce the specific content of XPath.