A summary of XSLT knowledge

Source: Internet
Author: User
Tags empty expression include string sort variable xpath xsl

<!--[if!supportlists]-->²<!--[endif]-->xslt element

<!--[if!supportlists]--> one, <!--[endif]-->xsl:if: Simple conditional 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 that, if true, performs the action expressed by the content of the xsl:if, or false without any action.

A logical expression can be a script judgment statement, or a node or attribute in the source data, or a node or attribute in the source data, and the XSLT execution engine automatically converts the value of the node or attribute to a Boolean value, which is then judged.

Must select

<!--[if!supportlists]-->3, <!--[endif]--> element information:

Number of occurrences: unrestricted

Parent elements: 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]--> II, <!--[Endif]-->xsl:for-each: Iterate over a template rule, that is, to iterate over each node in a set of nodes.

<!--[if!supportlists]-->1, <!--[endif]--> declaration method:

<xsl:for-each

select = Expression>

</xsl:for-each>

Part of the element description

<!--[if!supportlists]-->2, <!--[Endif]-->select:

An XPath expression that is used to select a series of source data nodes that meet the criteria in the current context and then process each node according to the content template rule.

<!--[if!supportlists]-->3, <!--[endif]--> element information:

Number of occurrences: unrestricted

Parent elements: 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]--> III, <!--[Endif]-->xsl:choose, Xsl:when, xsl:otherwise: Multiple conditional judgment combination elements

<!--[if!supportlists]-->1, <!--[endif]--> declaration method:

<xsl:choose>

<xsl:when

Test = boolean-expression>

</xsl:when>

<xsl:otherwise>

</xsl:otherwise>

</xsl:choose>

Part of the element description

<!--[if!supportlists]-->2, <!--[Endif]-->test:

Logical judgment expression, refer to the Test property description in Xsl:if.

<!--[if!supportlists]-->3, <!--[endif]--> notes:

The role of Xsl:choose, Xsl:when, and Xsl:otherwise is similar to the role of switch, case, and default in programming languages. The xsl:when can appear multiple times, while xsl:otherwise is selectable and can occur at most once.

<!--[If!supportlists]--> IV, <!--[endif]-->xsl:value-of: Gets the value of the selected node to be inserted into the output information as text.

<!--[if!supportlists]-->1, <!--[endif]--> declaration method:

<xsl:value-of

select = Expression

disable-output-escaping = "Yes" | "No"

</xsl:value-of>

Part of the element description:

<!--[if!supportlists]-->2, <!--[Endif]-->select:

An expression.

If the expression represents a node in the current context, the node is converted to a string (gets the value of the node) output.

If the expression represents a collection of nodes in the current context, the first node in the collection is converted to a string output.

The expression can also be a script statement or a constant, the system automatically evaluates the result of the statement and converts the result to string output.

<!--[if!supportlists]-->3, <!--[endif]-->disable-output-escaping:

The output information is an escape character, the default is no, and if yes, the contents of the Select are output as an escape character, for example: <xsl:value-of disable-output-escaping= "yes" select= "string" (' < ') the/> will output a "<".

<!--[if!supportlists]-->4, <!--[endif]--> element information:

Number of occurrences: unrestricted

Parent elements: 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]--> v <!--[Endif]-->xsl:template: Defines a Data transformation rule template element that can be reused.

<!--[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 should be globally unique. If a template transformation rule has a name, it can but generally does not need to have a "match" attribute. The Name property is typically used with <xsl:call-template>.

<!--[if!supportlists]-->3, <!--[Endif]-->match:

An XPath expression that determines under what circumstances the template conversion rule is used. If there is no "name" attribute, the "match" attribute is required.

<!--[if!supportlists]-->4, <!--[endif]-->priority:

Precedence of template rules, if there are multiple templates with the same "match", then <xsl:apply-templates> filters according to the precedence of the template transformation rules. 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 pattern, 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 always exceeds the default priority.

<!--[if!supportlists]-->5, <!--[Endif]-->mode:

The pattern value of the template rule. The general "mode" is used in conjunction with the <xsl:apply-templates> "mode": if <xsl:apply-templates> has the "mode" attribute, then it is only from those with the same
The template rule for the mode value, and if <xsl:apply-templates> does not have a "mode" attribute, it is filtered only from the template rules that do not have the "mode" attribute.

<!--[if!supportlists]-->6, <!--[endif]--> element information:

Element Number: 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]--> notes:

<xsl:template> can use <xsl:param> child elements with <xsl:call-template> and <xsl:apply-templates> <xsl: With-param> the child element to perform a parameter invocation operation in a similar program.

<!--[if!supportlists]--> VI, <!--[endif]-->xsl:call-template:: Invoke 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: unrestricted

Parent elements: 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]--> notes:

An error is thrown if the <xsl:template> of multiple identical "name" attributes is obtained.

Child element <xsl:with-param> Use method Reference <xsl:template> the Memo Information section.

<!--[if!supportlists]--> VII <!--[endif]-->xsl:apply-templates: Instructs the XSLT parser to select the appropriate template conversion rules based on the content and type of each selection node &L T;xsl:template> the call.

<!--[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 that selects the appropriate set of nodes and then calls the corresponding <xsl:template> to the node for data conversion processing respectively.

<!--[if!supportlists]-->3, <!--[Endif]-->mode:

Specific reference <xsl:template> "mode" Property description.

<!--[if!supportlists]-->4, <!--[endif]--> element information:

Number of occurrences: unrestricted

Parent elements: 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:sort, xsl:with-param

<!--[if!supportlists]-->5, <!--[endif]--> notes:

If a node has multiple <xsl:template>, it is determined according to the <xsl:tempate> priority ("priority" attribute) if there are multiple equal priority <xsl:template> Then choose the last <xsl:template>.

If no suitable <xsl:template> is found, the XSLT parser automatically joins the text of the current node and its child nodes and outputs it to the target data, equivalent to calling <xsl:valueof select = "." />. XSLT defines several templates that are generated by default to each transformation, regardless of whether you explicitly provide them. These templates are called XSLT's built-in templates. Each type of node (element, attribute, processing instruction, comment, and so on) that may be processed in an XML document has a built-in template. However, these built-in templates may have the lowest priority, so they will never be used when the user-supplied templates match the same node (see the previous issue on conflict resolution). Use them only if there are no other templates that match specific nodes.

You can sort the set of nodes for the output using <xsl:sort>.

A description of the use of the sub-genus <xsl:with-param> See the Remarks section of <xsl:template>.

<!--[if!supportlists]--> VIII, <!--[Endif]-->xsl:param: Parameter elements

<!--[if!supportlists]-->1, <!--[endif]--> declaration method:

<xsl:param

Name = QName

select = Expression>

</xsl:param>

Partial attribute Description

<!--[if!supportlists]-->2, <!--[Endif]-->name:

The name of the parameter must be globally unique and required. How to use the parameter: $param-name.

<!--[if!supportlists]-->3, <!--[Endif]-->select:

An XPath expression that obtains the corresponding node element from the current context and, if no corresponding node exists, the default value of Param is null. If the select exists, then the contents of the <xsl:param〉 must be empty.

<!--[if!supportlists]-->4, <!--[endif]--> element information:

Number of occurrences: unrestricted

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]--> notes:

(1) The use of the parameters: $param-name

(2) The Select property of <xsl:param> and non-empty content cannot exist at the same time.

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

(4) <xsl:param> has its own scope, scoped by the parent element.

(5) <xsl:param> can use the XSLT parser to set values externally, using methods to refer to the use of System.Xml.Xsl.XsltArgumentList classes.

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

<!--[If!supportlists]--> IX, <!--[Endif]-->xsl:with-param: Pass a parameter value to a <xsl:template>.

<!--[if!supportlists]-->1, <!--[endif]--> declaration method:

<xsl:with-param

Name = QName

select = Expression>

</xsl:with-param>

<!--[if!supportlists]-->2, <!--[endif]--> Property Description Reference <xsl:param>

<!--[if!supportlists]-->3, <!--[endif]--> element information:

Number of occurrences: unrestricted

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: variable element, 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]--> properties are fully consistent with <xsl:param>, specifically see <xsl:param>

<!--[if!supportlists]-->3, <!--[endif]--> element information:

Number of occurrences: unrestricted

Parent elements: 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]--> notes:

<xsl:param> and <xsl:variable> are used in the same way as they do, but there are the following differences:

(1) <xsl:param> use less occasions (only Xsl:stylesheet, Xsl:template, Xsl:transform), while <xsl:variable> use more occasions.

(2) <xsl:param> can set its specific value from the outside through the XSLT parser, and it can modify its default value through <xsl:with-param> in the template, while <xsl:variable> does not have this capability.

<!--[if!supportlists]--> 11, <!--[Endif]-->xsl:import, Xsl:include: Import external transformation 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 XSLT file being imported.

<!--[if!supportlists]-->3, <!--[endif]--> element information:

Number of occurrences: unrestricted

Parent element: Xsl:stylesheet, Xsl:transform

Child elements: None

<!--[if!supportlists]-->4, <!--[endif]--> notes:

<!--[if!supportlists]--> <!--[Endif]-->import and include must be top-level elements, and if import and include exist at the same time, import must be in Clude before the declaration.

<!--[if!supportlists]--> <!--[Endif]-->import The main difference with include is that the include is in exactly the same position as the template in the imported style sheet (with the same Default priority), there is no difference, but import imported templates have a lower default priority.

<!--[If!supportlists]--> 12, <!--[Endif]-->xsl:apply-imports: Excellent invokes the overloaded conversion rule template element from the inserted style sheet.

<!--[if!supportlists]-->1, <!--[endif]--> declaration method:

<xsl:apply-imports/>

<!--[if!supportlists]-->2, <!--[endif]--> element information:

Number of occurrences: unrestricted

Parent elements: 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: None

<!--[if!supportlists]-->3, <!--[endif]--> notes:

The XSLT parser takes precedence over the import's stylesheet to find templates that match the criteria, if the template does not exist in the import's style sheet, and then looks for a qualifying template from the original style sheet.

<!--[if!supportlists]--> 13, <!--[Endif]-->xsl:copy, xsl:copy-of: Copy source node data is inserted 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:

A property collection name, or a space-delimited number of property names.

<!--[if!supportlists]-->3, <!--[Endif]-->select:

An XPath expression that gets the portion of the xsl:copy-of used to copy to the target data. If the result of the settlement is a collection of nodes, then copy-of copies all of the nodes and their properties and child nodes to the target data in the original order, and writes the value to the target data if the result is a value. If the XPath expression is illegal, no action is made.

<!--[if!supportlists]-->4, <!--[endif]--> element information:

Xsl:copy:

Number of occurrences: unrestricted

Parent elements: 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-of:

Number of occurrences: unrestricted

Parent elements: 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: None

<!--[if!supportlists]-->5, <!--[endif]--> notes:

(1), xsl:copy: The target data will be created in the same name, data type, namespace of the node, but the current node text information, child nodes, attributes are not automatically copied to the Target data node.

(2), xsl:copy-of: When its "select" Property settlement result is a node in the source data or a collection of nodes, it will be the node or node set and its attributes and child nodes in the same order safe copy to the target data. This is also the main difference between xsl:copy-of and xsl:copy, and if the result of the calculation is a worthwhile time, it will output the value to the target data.

<!--[if!supportlists]--> 14, <!--[endif]-->xsl:sort: Node collection sort elements.

<!--[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 key to use for the node (node itself, child nodes, attributes, or other related nodes) and xsl:sort if the settlement result is not a node.

<!--[if!supportlists]-->3, <!--[Endif]-->lang:

The sort of language used, different languages have different sort comparison algorithms.

<!--[if!supportlists]-->4, <!--[Endif]-->data-type:

Sorts the data type of the node that uses the key.

<!--[if!supportlists]-->5, <!--[Endif]-->order:

Ascending or Descending

<!--[if!supportlists]-->6, <!--[Endif]-->case-order:

String capitalization processing method.

<!--[if!supportlists]-->7, <!--[endif]--> element information:

Element Number: Unlimited

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

Child element: None.

<!--[if!supportlists]-->8, <!--[endif]--> notes:

The sort algorithm ignores the dash ('-').

<!--[if!supportlists]--> 15, <!--[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:

The name of the new output element, which is a QName. Must select

<!--[if!supportlists]-->3, <!--[Endif]-->namespace:

The namespace URI of the newly created output element. If the prefix (prefix) in name is not empty, the special prefix is bound to the namespace URI.

<!--[if!supportlists]-->4, <!--[Endif]-->use-attribute-sets:

Property collection name, sets the property collection for the new output element, and separates with spaces if there are multiple property collection names.

<!--[if!supportlists]-->5, <!--[endif]--> element information:

Element Number: Unlimited

Parent elements: 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 collection 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:

The property collection 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.