|
The <xsl:if> element is used to put a conditional test against the content of the XML file. The <xsl:if> Element
|
<xsl:if test="expression"> |
Where to Put the <xsl:if> Element
<xsl:if>元素应该放在哪
To add a conditional test, add the <xsl:if> element inside the <xsl:for-each> element in the XSL file:
如果要添加一个条件语句,那么就必须在XSL文件里的<xsl:for-each>中添加一个<xsl:if>元素:
<?xml version="1.0" encoding="ISO-8859-1"?> |
Note: The value of the required test attribute contains the expression to be evaluated.
注意: 所要求的(test)属性值包括了所计算的表达式的值。
The code above will only output the title and artist elements of the CDs that has a price that is higher than 10.
上述代码仅输出价格高于10的CD所对应的标题和艺术家。
The result of the transformation above will look like this:
上述代码的转换结果如下:
My CD Collection
我的CD集
| Title | Artist |
|---|---|
| Empire Burlesque | Bob Dylan |
| Still got the blues | Gary Moore |
| One night only | Bee Gees |
| Romanza | Andrea Bocelli |
| Black Angel | Savage Rose |
| 1999 Grammy Nominees | Many |
View the XML file, View the XSL file, and View the result
XML文件, XSL文件, 以及 最终结果
