最新国产好看的视频,伊人天堂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)文章

最新評論

云浮市| 固镇县| 喀什市| 渑池县| 高密市| 花莲县| 仪征市| 巫山县| 武威市| 土默特左旗| 南汇区| 江北区| 巴中市| 上高县| 页游| 鱼台县| 广昌县| 会泽县| 改则县| 温泉县| 泽普县| 即墨市| 鹤壁市| 繁峙县| 麟游县| 满洲里市| 恩平市| 抚松县| 安龙县| 美姑县| 嘉善县| 达孜县| 土默特左旗| 武穴市| 镇坪县| 临江市| 京山县| 武穴市| 金昌市| 林口县| 博罗县|