Template rules for XSL

Source: Internet
Author: User
Tags xsl
Template

The text content within the <xsl:template> label describes the form of the transformation result, called the output template. The value of the attribute match compares the template rule to the specified element or attribute, only the matching DOM nodes are processed, and the remaining nodes are ignored. The root node of the tree is the first match in the process, and the root node is represented by "/":

<xsl:template match= "/" >
Output template for root element
</xsl:template>

Then match the other nodes, at which point the name of the element object to be processed is indicated in quotation marks. If a "*" appears in quotation marks, it means that the rule applies to all element nodes that are not individually specified for processing. For example, the second template in the following example indicates that all nodes except the <Employee> element are to be processed:

<xsl:template match= "Employee" >
Output template
</xsl:template>
<xsl:template match= "*" >
Output template
</xsl:template>

In addition, you can use the path designator in the XSL to specify that elements of a particular location match the template. "//" represents an arbitrary depth position, such as <xsl:template match= "//employee" > The <Employee> element used to match any position in the document; if <xsl:template match= " Employee//name "indicates that all <Name> elements in the successor node of the <Employee> element are matched. Another path indicator is "/", which indicates a direct parent-child node relationship. Changing the "//" to "/" in the example above means that the <Name> element in the <Employee> element child node is matched.

Obviously, some tree nodes may correspond to multiple templates in the XSL, in which case only the last corresponding template will take effect, and the preceding template rule will be ignored by the XSL processor.

"/" is a node that represents the current document, similar to a DOS directory separator. For example,/people represents the selection of the people element under the root node, and People/person represents all Peson child elements under people element selection.

"//" represents all nodes in the current document. Similar to view the entire directory. For example,//people represents the selection of all people elements in a document, regardless of its level, and People//person represents all the person elements under the people element, regardless of how deep it is.



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.