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

XSLT <xsl:choose> 元素

定義和用法

<xsl:choose> 元素與 <xsl:when> 以及 <xsl:otherwise> 元素結(jié)合,可表達(dá)多重條件測(cè)試。

如果沒(méi)有 <xsl:when> 是 true,則處理 <xsl:otherwise> 的內(nèi)容。

如果沒(méi)有 <xsl:when> 是 true,且不存在 <xsl:otherwise> 元素,則不創(chuàng)建任何內(nèi)容。

提示:對(duì)于簡(jiǎn)單的條件測(cè)試,請(qǐng)使用 <xsl:if> 元素取而代之。

語(yǔ)法

<xsl:choose>
<!-- Content:(xsl:when+,xsl:otherwise?) -->
</xsl:choose>

屬性

None

實(shí)例

例子 1

下面的代碼會(huì)在 CD 的價(jià)格高于 10 時(shí),向 artist 列添加粉色的背景色:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <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 test="price &gt; 10">
            <td bgcolor="#ff00ff">
            <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>

查看 XML 文件,查看 XSL 文件,查看結(jié)果。

例子 2

聲明名為 "color" 的變量。把這個(gè)變量的值賦值到 current 元素的 color 屬性。如果 current 元素沒(méi)有 color 屬性,則 color 的值是 "green":

<xsl:variable name="color">
  <xsl:choose>
    <xsl:when test="@color">
      <xsl:value-of select="@color"/>
    </xsl:when>  
    <xsl:otherwise>green</xsl:otherwise>
  </xsl:choose>
</xsl:variable>
佛学| 甘德县| 车险| 安宁市| 民勤县| 苍梧县| 高邑县| 平定县| 军事| 务川| 天峨县| 上饶县| 长泰县| 镇坪县| 通辽市| 京山县| 三台县| 龙门县| 望都县| 香港| 天峻县| 鹤庆县| 罗城| 墨脱县| 泰宁县| 大竹县| 陆河县| 大新县| 兴隆县| 龙门县| 建阳市| 凉山| 石阡县| 峨边| 宁安市| 磐安县| 乳源| 息烽县| 鞍山市| 清丰县| 平潭县|