Learn from me. Choose in XSL (5) XSL

Source: Internet
Author: User
Tags expression xsl

In the last period we learned about the XSL element <xsl:if>, we have been able to test the value of XML data to determine the different output form, I do not know whether you have tried, actually <xsl:for-each> can also partially implement <xsl:if> functions, but sometimes , we want to test multiple conditions at the same time, and output corresponding results according to different conditions. Of course, we can use if if we only have if available. Fortunately we have a better choice, that is to use <xsl:choose>. The syntax for the related elements is described below:
<xsl:choose>
Grammar:<xsl:choose>
Properties: None, representing the start of a multiple-selection test

<xsl:when>
Grammar:
<xsl:when expr= "script-expression" language= "language-name" test= "pattern" >
Property:
expr── a script language expression that evaluates to True or false, and if the result is true, and the content is displayed in the output (this property can be omitted).
The script language type of an expression in the Language──expr property, with the same value as the Language property of the HTML tag script, and the default is JScript.
test── source data test conditions.

<xsl:otherwise>
Grammar:<xsl:otherwise>
Properties: None, in a multiple-selection test, if there are no conditions that do not meet the <xsl:when>, if the tag is at the end, the contents of the tag are output.

Example:

In this case, the student report card, for example, requires excellent (>85), General (70~85), passing (60~69), failing (< 60), rather than showing the score according to the level of achievement. One of the transcripts of the XML document (filename: grade.xml) is as follows:
<?xml version= "1.0" encoding= "GB2312"?>
<?xml-stylesheet type= "text/xsl" href= "grade.xsl"?>
<document>
<grade>
<name> Big Fat </name>
<english>80</english>
<math>90</math>
<chymest>90</chymest>
</grade>
<grade>
<name> Floret </name>
<english>98</english>
<math>70</math>
<chymest>85</chymest>
</grade>
</document>

The XSL document (filename: grade.xsl) reads as follows for the implementation to be displayed by fractional rank:

<?xml version= "1.0" encoding= "GB2312"?>
<xsl:stylesheet xmlns:xsl= "Http://www.w3.org/TR/WD-xsl" >
<xsl:template match= "/" >
<HTML>
<HEAD><TITLE> Transcript </TITLE></HEAD>
<BODY>
<xsl:apply-templates select= "Document"/>
</BODY>
</HTML>
</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.