原著:Jan Egil Refsnes 翻译:阿捷 七. XSL 的控制语句 1.条件语句if…then 上面的例子改写成为: 2. XSL 的Choose <xsl:choose> 上面的例子改写成为:
XSL同样还有条件语句(呵呵~~好厉害吧,象程序语言一样)。具体的语法是增加一个xsl:if元素,类似这样
<xsl:if match=”.[ARTIST=Bob Dylan]”>
… some output …
</xsl:if>
<?xml version=1.0?>
<xsl:stylesheet xmlns:xsl=”http://www.w3.org/TR/WD-xsl”>
<xsl:template match=”/”>
<html>
<body>
<table border=”2″ bgcolor=”yellow”>
<tr>
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select=”CATALOG/CD”>
<xsl:if match=”.[ARTIST=Bob Dylan]”>
<tr>
<td><xsl:value-of select=”TITLE”/></td>
<td><xsl:value-of select=”ARTIST”/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
choose的用途是出现多个条件,给出不同显示结果。具体的语法是增加一组xsl:choose,xsl:when,xsl:otherwise元素:
<xsl:when match=”.[ARTIST=Bob Dylan]”>
… some code …
</xsl:when>
<xsl:otherwise>
… some code ….
</xsl:otherwise>
</xsl:choose>
<?xml version=1.0?>
<xsl:stylesheet xmlns:xsl=”http://www.w3.org/TR/WD-xsl”>
<xsl:template match=”/”>
<html>
<body>
<table border=”2″ bgcolor=”yellow”>
<tr>
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select=”CATALOG/CD”>
<tr>
<td><xsl:value-of select=”TITLE”/></td>
<xsl:choose>
<xsl:when match=”.[ARTIST=Bob Dylan]”>
<td bgcolor=”#ff0000″><xsl:value-of select=”ARTIST”/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select=”ARTIST”/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
xsl简明教程(7)xsl 的控制语句_xsl教程
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » xsl简明教程(7)xsl 的控制语句_xsl教程
相关推荐
- 暂无文章
