Easy Introduction to XSLT Chapter III: The element syntax of XSLT

Source: Internet
Author: User
Tags execution xsl xslt

With the introduction of the previous two chapters, we have some understanding of the basic concepts of XSLT and its transformation process. Let's learn the specific syntax of XSLT together. When it comes to grammar, it's always boring, and you can go through it in general, and then look at it when you really need to use XSLT.

element syntax for 3.XSLT

3.1 Xsl:template and Xsl:apply-templates

3.2 xsl:value-of

3.3 Xsl:for-each

3.4 xsl:if

3.5 Xxsl:choose, when, otherwise

3.6 Xsl:sort

3.1 Xsl:template and Xsl:apply-templates

Template (template) is one of the most important concepts in XSLT. An XSLT file is made up of one template, and any XSLT file contains at least one template. The concept of a template is like building blocks; If you are a programmer, you can also consider a template as a method, a class, or a module. They can be assembled or individually grouped, and different templates control different output formats.

The template (template) consists of two parts: match pattern and execution. The simple schema defines which nodes in the XML source document will be processed by the template, and the execution defines what format the output is. The corresponding syntax for two parts is xsl:template and xsl:apply-templates.

The syntax for xsl:template is:

<xsl:template
match = pattern
name = qname
priority = number
mode = qname>
<!-- 执行内容 -->
</xsl:template>

The role of Xsl:template is to define a new template. property, and mode is used to distinguish different templates that match the same node. \ name,priority They are not commonly used properties. The Match property controls the template's matching mode (pattern), which is used to locate which node in the XML source document is being processed by the template. A template matches a node. We use an example to help understand:

Let's say we're working with a chapter and paragraph document. We define the paragraphs with the Para element and define the chapters with the chapter elements. Let's look at the possible values for the match attribute. The following statement describes the template matching all para elements

<xsl:template match= "Para" >

</xsl:template>

The following statement illustrates that the template matches all the para elements and all the chapter elements:

<xsl:template match= "(Chapter|para)" >

</xsl:template>

The following statement describes the template that matches all para elements that are chapter elements of the parent node:

<xsl:template match= "Chapter//para" >

</xsl:template>

The following statement describes the template matching root node:

<xsl:template match= "/" >

</xsl:template>

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.