One of the advantages of XML technology is the selectivity of data output, that is, to select the required data output. The selection pattern statement:<xsl:for-each>, <xsl:value-of>, and <xsl:apply-template> that we talked about earlier simply select the nodes that arrive through the "/" symbol layer. If we do not need all of the XML data output, and only need to meet a certain condition of some of the data, "radish greens, to do everything", then conditional judgment <xsl:if> and multiple conditions of judgment <xsl:choose> and <xsl:when> To cater to this need, if you are familiar with the design, you will find them familiar.
If in XSL, first, introduce the syntax structure of the XSL element <xsl:if>:
Grammar:
<xsl:if 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.
Example:
This is in the case of a report named Report.xml, which reads as follows:
<?xml version= "1.0" encoding= "GB2312"?>
<?xml-stylesheet type= "text/xsl" href= "report.xsl"?>
<document>
<report>
<class>
Jia ban
</class>
<q1>50</q1>
<q2>70</q2>
<q3>30</q3>
<q4>10</q4>
</report>
<report>
<class>
Class B
</class>
<q1>20</q1>
<q2>30</q2>
<q3>40</q3>
<q4>50</q4>
</report>
<report>
<class>
Class C
</class>
<q1>70</q1>
<q2>40</q2>
<q3>20</q3>
<q4>10</q4>
</report>
</document>
We use the XSL template in conjunction with the <xsl:if> we learned today, and write an XSL document for it, requiring a quarterly yield of less than or equal to 20 in red, the file name is report.xsl and the contents are as follows: