国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

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

2019-11-18 20:03:14
字體:
來源:轉載
供稿:網友
原著: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的用途是出現多個條件,給出不同顯示結果。具體的語法是增加一組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>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 无极县| 锦屏县| 全南县| 彭山县| 锦屏县| 广水市| 嘉峪关市| 吉水县| 桓仁| 博爱县| 衢州市| 衡水市| 五河县| 镇雄县| 株洲县| 潼南县| 惠安县| 安阳县| 富蕴县| 新绛县| 耒阳市| 衡东县| 乐亭县| 古丈县| 江永县| 长治市| 大英县| 安岳县| 南昌市| 乌鲁木齐县| 晋中市| 梅州市| 大埔区| 灵璧县| 汉阴县| 峨眉山市| 城市| 峨眉山市| 诏安县| 安顺市| 清水河县|