XSLT knowledge Summary

Source: Internet
Author: User
Tags processing instruction xslt xslt parser

<! -- [If! SupportLists] --> 2 <! -- [Endif] --> XSLT Element
<! -- [If! SupportLists] --> 1. <! -- [Endif] --> xsl: If: A simple condition judgment element.

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: if

Test = boolean-Expression>

</Xsl: if>

Partial attribute description:

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> Test

A logical expression. if it is true, the operation expressed by the content of xsl: if is executed. if it is false, no operation is performed.

A logical expression can be used to determine a statement for a script or a node or attribute in the source data. If it is a node or attribute in the source data, then, the xslt execution engine automatically converts the value of a node or attribute to a Boolean value before making a judgment.

Required

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> element information:

Number of occurrences: Unlimited

Parent element: xsl: attribute, xsl: comment, xsl: copy, xsl: element, xsl: fallback, xsl: for-each, xsl: if, xsl: message, xsl: otherwise, xsl: param, xsl: processing-instruction, xsl: template, xsl: variable, xsl: when, xsl: with-param, output elements

Child elements: xsl: apply-templates, xsl: attribute, xsl: call-template, xsl: choose, xsl: comment, xsl: copy, xsl: copy-of, xsl: element, xsl: for-each, xsl: if, xsl: processing-instruction, xsl: text, xsl: value-of, xsl: variable, output elements

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> xsl: for-each: cyclically executes elements of a template rule, that is, processes each node in a node set cyclically.

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: for-each

Select = Expression>

</Xsl: for-each>

Partial Element description

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> select:

An xpath expression is used to select a series of source data nodes that meet the conditions in the current context, and process each node according to the content template rules.

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> element information:

Number of occurrences: Unlimited

Parent element: xsl: attribute, xsl: comment, xsl: copy, xsl: element, xsl: fallback, xsl: for-each, xsl: if, xsl: message, xsl: otherwise, xsl: param, xsl: processing-instruction, xsl: template, xsl: variable, xsl: when, xsl: with-param, output elements

Child elements: xsl: apply-imports, xsl: apply-templates, xsl: attribute, xsl: call-template, xsl: choose, xsl: comment, xsl: copy, xsl: copy-of, xsl: element, xsl: fallback, xsl: for-each, xsl: if, xsl: message, xsl: number, xsl: processing-instruction, xsl: sort, xsl: text, xsl: value-of, xsl: variable

 

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> xsl: choose, xsl: when, xsl: otherwise: Multi-condition judgment combination Element

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: choose>

<Xsl: when

Test = boolean-Expression>

</Xsl: when>

<Xsl: otherwise>

</Xsl: otherwise>

</Xsl: choose>

Partial Element description

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> test:

For a logical judgment Expression, see the test attribute description in xsl: if.

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> note:

Xsl: choose, xsl: when, and xsl: otherwise act like switches, cases, and defaults in programming languages. The xsl: when can appear multiple times, while the xsl: otherwise can be selected and can appear at most once.

 

<! -- [If! SupportLists] --> 4. <! -- [Endif] --> xsl: value-of: gets the value of the selected node and inserts it into the output information as text.

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: value-

Select = Expression

Disable-output-escaping = "yes" | "no"

</Xsl: value-of>

Some elements are described as follows:

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> select:

An expression.

If the expression indicates a node in the current context, the node is converted into a string (get the value of the node) and output.

If the expression is the current context node set, the first node in the set is converted into a string output.

This expression can also be a script statement or a constant. Then, the system automatically calculates the result of the statement and converts the result to a string for output.

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> disable-output-escaping:

Whether the output information is an escape character. The default value is no. If yes, the content in select is output as an escape character. For example: <xsl: value-of disable-output-escaping = "yes" select = "string ('& lt;')"/> A "<" is output.

<! -- [If! SupportLists] --> 4, <! -- [Endif] --> element information:

Number of occurrences: Unlimited

Parent element: xsl: attribute, xsl: comment, xsl: copy, xsl: element, xsl: fallback, xsl: for-each, xsl: if, xsl: message, xsl: otherwise, xsl: param, xsl: processing-instruction, xsl: template, xsl: variable, xsl: when, xsl: with-param, output elements

Child element: none.

<! -- [If! SupportLists] --> 5. <! -- [Endif] --> xsl: template: defines a reusable data conversion rule template element.

 

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: template

Name = Qname

Match = Pattern

Priority = number

Mode = QName

</Xsl: template>

Partial attribute description:

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> name:

The name of the template rule, which must be globally unique. If a template conversion rule has a name, it can but generally does not need the "match" attribute. The Name attribute is generally used in combination with <xsl: call-template>.

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> match:

An xpath expression that determines under what circumstances the template conversion rule is used. If the "name" attribute is not available, the "match" attribute is required.

<! -- [If! SupportLists] --> 4, <! -- [Endif] --> priority:

Template rule priority. If multiple templates with the same "match" exist, <xsl: apply-templates> filters the template based on the template conversion rule priority. If no priority is explicitly specified, the processor calculates a default value for the template. The default priority range specified by the processor is from-0.5 to + 0.5. Basically, the more special the mode is, the higher the default priority. Because the range is from-0.5 to + 0.5, If you explicitly specify a template with a priority of 1, it will always exceed the default priority.

<! -- [If! SupportLists] --> 5, <! -- [Endif] --> mode:

The mode Value of the template rule. Generally, the "mode" is used in combination with the "mode" of <xsl: apply-templates>. If <xsl: apply-templates> has the "mode" attribute
Filter the template rules with the "mode" value. If <xsl: apply-templates> does not have the "mode" attribute, then, it only filters out template rules without the "mode" attribute.

 

<! -- [If! SupportLists] --> 6. <! -- [Endif] --> element information:

Number of elements: Unlimited

Parent element: xsl: stylesheet, xsl: transform

Child elements: xsl: apply-imports, xsl: apply-templates, xsl: attribute, xsl: call-template, xsl: choose, xsl: comment, xsl: copy, xsl: copy-of, xsl: element, xsl: fallback, xsl: for-each, xsl: if, xsl: message, xsl: number, xsl: param, xsl: processing-instruction, xsl: text, xsl: value-of, xsl: variable, output elements

 

<! -- [If! SupportLists] --> 7. <! -- [Endif] --> note:

<Xsl: template> the <xsl: param> sub-elements can be used in the same way as <xsl: call-template> and <xsl: apply-templates> <xsl: with-param> sub-elements are used to call parameters in similar programming.

<! -- [If! SupportLists] --> 6. <! -- [Endif] --> xsl: call-template: calls an element of a template conversion rule with the same "name" attribute.

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: call-template

Name = QName>

</Xsl: call-template>

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> element information:

Number of occurrences: Unlimited

Parent element: xsl: attribute, xsl: comment, xsl: copy, xsl: element, xsl: fallback, xsl: for-each, xsl: if, xsl: message, xsl: otherwise, xsl: param, xsl: processing-instruction, xsl: template, xsl: variable, xsl: when, xsl: with-param, output elements

Child element: xsl: with-param

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> note:

If you obtain multiple <xsl: template> with the same "name" attribute, an error is thrown.

For how to use the sub-element <xsl: with-param>, see the remarks section of <xsl: template>.

<! -- [If! SupportLists] --> 7. <! -- [Endif] --> xsl: apply-templates: guides the xslt parser to select an appropriate template conversion rule <xsl: template> Based on the content and type of each selected node for calling.

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: apply-templates

Select = Expression

Mode = QName>

</Xsl: apply-templates>

Partial attribute description

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> select:

An xpath expression selects an appropriate node set and then calls the corresponding <xsl: template> to convert the data of the node.

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> mode:

For more information, see <xsl: template>'s "mode" attribute description.

 

<! -- [If! SupportLists] --> 4, <! -- [Endif] --> element information:

Number of occurrences: Unlimited

Parent element: xsl: attribute, xsl: comment, xsl: copy, xsl: element, xsl: fallback, xsl: for-each, xsl: if, xsl: message, xsl: otherwise, xsl: param, xsl: processing-instruction, xsl: template, xsl: variable, xsl: when, xsl: with-param, output elements

Child element: xsl: sort, xsl: with-param

<! -- [If! SupportLists] --> 5, <! -- [Endif] --> note:

If a node has multiple <xsl: template> values, the values are determined based on the priority ("priority" attribute) of <xsl: tempate>, if there are multiple <xsl: template> with the same priority, select the last <xsl: template>.

If no suitable <xsl: template> is found, the xslt parser automatically connects the text of the current node and Its subnodes and outputs the text to the target data, which is equivalent to calling <xsl: valueof select = ". "/>. XSLT defines several templates that are generated to each transformation by default (whether explicitly provided or not ). These templates are called built-in XSLT templates. Each type of node (element, attribute, processing instruction, comment, etc.) processed in the XML document may have a built-in template. However, these built-in templates may have the lowest priority, so they will never be used when the templates provided by the user match the same node (see the previous issue about conflict resolution ). These templates are used only when no template matches a specific node.

You can use <xsl: sort> to sort the output node sets.

For the usage instructions of the sub-element <xsl: with-param>, see the remarks section of <xsl: template>.

<! -- [If! SupportLists] --> 8. <! -- [Endif] --> xsl: param: Parameter Element

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: param

Name = QName

Select = Expression>

</Xsl: param>

Partial attribute description

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> Name:

Parameter Name, which must be globally unique and required. Parameter usage: $ param-name.

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> Select:

An xpath expression that obtains the corresponding node element from the current context. If no corresponding node exists, the default value of param is null. If select exists, the content of <xsl: param> must be null.

<! -- [If! SupportLists] --> 4, <! -- [Endif] --> element information:

Number of occurrences: Unlimited

Parent element: xsl: stylesheet, xsl: template, xsl: transform

Child elements: xsl: apply-templates, xsl: attribute, xsl: call-template, xsl: choose, xsl: comment, xsl: copy, xsl: copy-of, xsl: element, xsl: for-each, xsl: if, xsl: processing-instruction, xsl: text, xsl: value-of, xsl: variable, output elements

<! -- [If! SupportLists] --> 5, <! -- [Endif] --> note:

(1) parameter usage: $ param-name

(2) The select attribute of <xsl: param> cannot coexist with non-empty content.

(3) If <xsl: param> has the "select" attribute, the value of this attribute must be an expression and the value calculated from this expression must be an object, otherwise, the value of this parameter is null.

(4) <xsl: param> has its own scope. The scope is determined by the parent element.

(5) <xsl: param> values can be set externally through the xslt parser. For details about how to use the parameter, refer to the usage of the System. Xml. Xsl. XsltArgumentList class.

(6) <xsl: param> can be used together with <xsl: with-param>.

<! -- [If! SupportLists] --> 9. <! -- [Endif] --> xsl: with-param: transmits a parameter value to <xsl: template>.

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: with-param

Name = QName

Select = Expression>

</Xsl: with-param>

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> for more information about attributes, see <xsl: param>

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> element information:

Number of occurrences: Unlimited

Parent element: xsl: apply-templates, xsl: call-template

Child elements: sl: apply-templates, xsl: attribute, xsl: call-template, xsl: choose, xsl: comment, xsl: copy, xsl: copy-of, xsl: element, xsl: for-each, xsl: if, xsl: processing-instruction, xsl: text, xsl: value-of, xsl: variable

<! -- [If! SupportLists] --> 10. <! -- [Endif] --> xsl: variable element, which binds an expression with a variable name.

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: variable

Name = QName

Select = Expression>

</Xsl: variable>

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> the usage and functions of attributes are exactly the same as those of <xsl: param>. For more information, see <xsl: param>

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> element information:

Number of occurrences: Unlimited

Parent element: xsl: attribute, xsl: comment, xsl: copy, xsl: element, xsl: for-each, xsl: if, xsl: otherwise, xsl: param, xsl: processing-instruction, xsl: stylesheet xsl: template, xsl: variable, xsl: when, xsl: with-param, output elements

Child elements: xsl: apply-templates, xsl: attribute, xsl: call-template, xsl: choose, xsl: comment, xsl: copy, xsl: copy-of, xsl: element, xsl: for-each, xsl: if, xsl: processing-instruction, xsl: text, xsl: value-of, xsl: variable, output elements

<! -- [If! SupportLists] --> 4, <! -- [Endif] --> note:

The usage and functions of <xsl: param> and <xsl: variable> are the same, but there are the following differences:

(1) <xsl: param> is rarely used (only xsl: stylesheet, xsl: template, xsl: transform), while <xsl: variable> is widely used.

(2) <xsl: param> you can use the xslt parser to set its specific values externally, and modify its default values in the template through <xsl: with-param>, <xsl: variable> does not have this capability.

<! -- [If! SupportLists] --> 11, <! -- [Endif] --> xsl: import, xsl: include: import external conversion template elements.

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: import href = "uri-reference"/>

<Xsl: include href = "uri-reference"/>

Attribute description:

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> href:

The location of the imported xslt file.

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> element information:

Number of occurrences: Unlimited

Parent element: xsl: stylesheet, xsl: transform

Child element: None

<! -- [If! SupportLists] --> 4, <! -- [Endif] --> note:

<! -- [If! SupportLists] --> <! -- [Endif] --> import and include must be top-level elements. If both import and include exist, import must be declared before include.

<! -- [If! SupportLists] --> <! -- [Endif] --> the main differences between import and include are: include and the template in the imported style sheet are in the same status (with the same default priority ), there is no difference, but the import template has a lower default priority.

 

<! -- [If! SupportLists] --> 12, <! -- [Endif] --> xsl: apply-imports: You can call the elements of the overloaded conversion rule template from the inserted style sheet.

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: apply-imports/>

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> element information:

Number of occurrences: Unlimited

Parent element: xsl: attribute, xsl: comment, xsl: copy, xsl: element, xsl: fallback, xsl: for-each, xsl: if, xsl: message, xsl: otherwise, xsl: param, xsl: processing-instruction, xsl: template, xsl: variable, xsl: when, xsl: with-param, output elements

Child element: None

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> note:

The Xslt parser first searches for qualified templates from the import style sheet. If the import style sheet does not have the corresponding template, it searches for the qualified templates from the original style sheet.

<! -- [If! SupportLists] --> 13, <! -- [Endif] --> xsl: copy, xsl: copy-of: Copies the source node data and inserts it into the target data element.

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: copy use-attribute-sets = QNames>

</Xsl: copy>

<Xsl: copy-of select = Expression/>

 

Partial attribute description:

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> use-attribute-sets:

Name of an attribute set, or multiple attribute names separated by a space.

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> select:

An xpath expression used to obtain the part of the xsl: copy-of file used to copy to the target data. If the settlement result is a node set, copy-of copies all the nodes, their attributes, and their subnodes to the target data in the original order; if the calculation result is a value, the value is written to the target data. If it is an invalid xpath expression, no operation is performed.

<! -- [If! SupportLists] --> 4, <! -- [Endif] --> element information:

Xsl: copy:

Number of occurrences: Unlimited

Parent element: xsl: attribute, xsl: comment, xsl: copy, xsl: element, xsl: fallback, xsl: for-each, xsl: if, xsl: message, xsl: otherwise, xsl: param, xsl: processing-instruction, xsl: template, xsl: variable, xsl: when, xsl: with-param, output elements

Child elements: xsl: apply-templates, xsl: attribute, xsl: call-template, xsl: choose, xsl: comment, xsl: copy, xsl: copy-of, xsl: element, xsl: for-each, xsl: if, xsl: processing-instruction, xsl: text, xsl: value-of, xsl: variable, output elements

 

Xsl: copy-:

Number of occurrences: Unlimited

Parent element: xsl: attribute, xsl: comment, xsl: copy, xsl: element, xsl: fallback, xsl: for-each, xsl: if, xsl: message, xsl: otherwise, xsl: param, xsl: processing-instruction, xsl: template, xsl: variable, xsl: when, xsl: with-param, output elements

Child element: None

<! -- [If! SupportLists] --> 5, <! -- [Endif] --> note:

(1). xsl: copy: A node with the same name, data type, and namespace as the current node will be created in the target data, however, the text information, subnodes, and attributes of the current node are not automatically copied to the target data node.

(2) xsl: copy-of: when the "select" attribute settlement result is a node or node set in the source data, it securely copies the node or node set, its attributes, and its subnodes to the target data in the same order. This is also the main difference between xsl: copy-of and xsl: copy. In addition, if the calculation result is a worthwhile value, it will output this value to the target data.

 

<! -- [If! SupportLists] --> 14, <! -- [Endif] --> xsl: sort: Sorting element of the node set.

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: sort

Select = string-Expression

Lang = {nmtoken}

Data-type = {"text" | "number" | QName}

Order = {"ascending" | "descending "}

Case-order = {"upper-first" | "lower-first "}

/>

Attribute description:

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> select:

An xpath expression that selects the keys used for sorting nodes (nodes themselves, subnodes, attributes, or other related nodes). If the settlement result is not a node, xsl: sort does not play any role.

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> lang:

The language used for sorting. Different Languages have different sorting comparison algorithms.

<! -- [If! SupportLists] --> 4, <! -- [Endif] --> data-type:

Sort the Data Type of the node corresponding to the key.

<! -- [If! SupportLists] --> 5, <! -- [Endif] --> order:

Ascending or descending

<! -- [If! SupportLists] --> 6. <! -- [Endif] --> case-order:

String case processing method.

 

<! -- [If! SupportLists] --> 7. <! -- [Endif] --> element information:

Number of elements: Unlimited

Parent element: xsl: apply-templates, xsl: for-each

Child element: none.

<! -- [If! SupportLists] --> 8, <! -- [Endif] --> note:

The sorting algorithm ignores dash ('-').

<! -- [If! SupportLists] --> 15th, <! -- [Endif] --> xsl: element: creates an output element with a special name.

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: element

Name = "element-name"

Namespace = "uri-reference"

Use-attribute-sets = QNames>

</Xsl: element>

Attribute description:

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> name:

Name of the new output element, which is a QName. Required

<! -- [If! SupportLists] --> 3. <! -- [Endif] --> namespace:

The namespace URI of the newly created output element. If the prefix in name is not empty, the special prefix will be bound together with the namespace Uri.

<! -- [If! SupportLists] --> 4, <! -- [Endif] --> use-attribute-sets:

Attribute Set Name, which sets an attribute set for the new output element. If Multiple Attribute Set names exist, separate them with spaces.

 

<! -- [If! SupportLists] --> 5, <! -- [Endif] --> element information:

Number of elements: Unlimited

Parent element: xsl: copy, xsl: element, xsl: fallback, xsl: for-each, xsl: if, xsl: message, xsl: otherwise, xsl: param, xsl: template, xsl: variable, xsl: when, xsl: with-param, output elements

Child elements: xsl: apply-templates, xsl: attribute, xsl: call-template, xsl: choose, xsl: comment, xsl: copy, xsl: copy-of, xsl: element, xsl: for-each, xsl: if, xsl: processing-instruction, xsl: text, xsl: value-of, xsl: variable, output elements

<! -- [If! SupportLists] --> 16, <! -- [Endif] --> xsl: attribute-set: attribute set element.

<! -- [If! SupportLists] --> 1. <! -- [Endif] --> declaration method:

<Xsl: attribute-set

Name = QName

Use-attribute-sets = QNames>

</Xsl: attribute-set>

Attribute description:

<! -- [If! SupportLists] --> 2. <! -- [Endif] --> name:

Attribute Set name, which is used by use-attribute-sets and xsl: use-attribute-sets.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.