最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

XSL簡明教程(7)XSL 的控制語句

 更新時間:2006年10月11日 00:00:00   作者:  
原著:Jan Egil Refsnes 翻譯:阿捷

七. XSL 的控制語句


1.條件語句if...then

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>


2. XSL 的Choose

choose的用途是出現(xiàn)多個條件,給出不同顯示結(jié)果。具體的語法是增加一組xsl:choose,xsl:when,xsl:otherwise元素:


<xsl:choose>

<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>

相關(guān)文章

最新評論

古交市| 丹阳市| 马边| 正阳县| 乐安县| 内黄县| 京山县| 晋江市| 崇文区| 曲周县| 梁河县| 泰和县| 嘉荫县| 兴城市| 胶州市| 连州市| 高青县| 左云县| 珲春市| 灌南县| 鲜城| 波密县| 中江县| 武乡县| 正宁县| 阿克陶县| 宁夏| 绵竹市| 龙南县| 博爱县| 平谷区| 荥阳市| 忻州市| 博罗县| 江油市| 潞西市| 通州区| 余江县| 西林县| 抚松县| 延寿县|