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>