当前位置: 首页 > 网络学院 > XML相关教程 > XSL/XSLT > <xsl:if>
The <xsl:if> element is used to put a conditional test against the content of the XML file.
<xsl:if>元素的作用是:根据XML文件的内容设置一个条件语句。
To put a conditional if test against the content of the XML file, add an <xsl:if> element to the XSL document.
如果你需要对XML文件的内容设置一个条件语句,那需要向XSL文档中添加一个<xsl:if>元素。
<xsl:if test="expression"> |
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:
上述代码的转换结果如下:
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文件, 以及 最终结果