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

Source: Internet
Author: User
Tags sort xsl xsl file xslt
Grammar

3.5 Xsl:choose, Xsl:when and Xsl:otherwise

The XSL:IF syntax does not have an else attribute. If we are going to make multiple choices, we need to use the Xsl:choose/xsl:when/xsl:otherwise series Process Control syntax. For specific use, see the following XSL file example:

<xsl:template match= "People" >

<xsl:choose>

<xsl:when test= "@name = ' Ajie '" >

<b><xsl:value-of select= "@name"/></b>

</xsl:when>

<xsl:when test= "@name" >

<i><xsl:value-of select= "@name"/></i>

</xsl:when>

<xsl:otherwise>

No name available

</xsl:otherwise>

<xsl:choose>

</xsl:template>

Description: First in the People node to find <name> attribute value of Ajie elements, if found, will ajie in bold output; If you do not find a <name> element with a value of Ajie, all <name> The value of the element is output in italics, and if no <name> element is found, the "no" is displayed.
Name available ".

3.6 Xsl:sort

In XSLT, the elements of an XML source document can be reordered, and the ordering syntax is xsl:sort. For example: The following code is to sort the document elements by name.

<xsl:template match= "People" >

<xsl:apply-templates select= "Person" >

<xsl:sort select= "@name"/>

</xsl:apply-templates>

</xsl:template>

These are the main syntaxes of the elements of XSLT, and many other syntaxes, such as import, include, element, attribute, number, param, and so on, are not explained here. Our aim is to give you a basic idea of the syntax of XSLT, and to understand XSLT as a powerful function of translating languages.



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.