Follow me. XSL (3) XSL templates and match patterns

Source: Internet
Author: User
Tags script tag sort what scripting xsl

After a few days of learning, we learned about the authoring of XHTML documents and three of XSL elements that have been able to write fairly flexible XSL documents, and today we will learn about the writing of XSL templates. As we all know, short documents and programs are very readable, but when scaled up, their complexity increases at a faster rate.

We have learned <xsl:for-each>, <xsl:value-of>, and so on, we can use them to achieve simple format output of XML data, but if you encounter more complex XML format output, the XSL in order to write down as required, First, the design is difficult, scalability is poor, not conducive to the division of labor between the cooperation between the other, can be modified very poor, may appear to lead the whole army of the situation, not conducive to maintenance. The process of modular design step-by-step refinement of the method here has been applied!

The XSL template refines the design of the XSL into a template (block) Finally, the templates (blocks) are combined into a complete XSL; like ships and containers, we don't pile up all the goods in pieces, we load them in separate containers and then pile them up on the ship. This method allows you to consider the overall design of the entire XSL, and then a number of forms into different modules, and then specifically design these modules, and finally integrate them together, so that the macro and micro, in line with the people of the Organization, standardization requirements.

Loading container--writing template (block):<xsl:template>

Grammar:
<xsl:template match= "Node-context" language= "Language-name" >

Property:

match── determine what circumstances to execute this template. As a simplified description, use the name of the tag here, where the top-level template must set the match to "/".

language── determines what scripting language is executed in this template with the same value as the Language property of the script tag in HTML, and the default value is JScript.

<xsl:template> use the match attribute to select a node from XML that satisfies the condition, and a template that forms a specific output form for these specific nodes. This article is from http://bianceng.cn (Getting started with programming)

Hanging container on board--calling template (block):<xsl:apply-templates>

Grammar:

<xsl:apply-templates select= "pattern" order-by= "sort-criteria-list" >

Property:

select── determines what template should be executed in this context, that is, select the template (block) that was established with the < Xsl:template > tag.

order-by── a sort standard separated by semicolons (;), usually a sequence of child tags.

Example:

Take a personal resume as an example, in order to facilitate the process we would like to "skills" each item is tagged to <skill></skill> around, how many skills there are many of these tags on, after the revised resume XML document contents are as follows:

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.