亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

XSLT <xsl:if> 元素

定義和用法

<xsl:if> 包含了一個(gè)模板,只有指定的條件成立時(shí),才應(yīng)用此模板。

提示:請使用 <xsl:choose> 與 <xsl:when> 和 <xsl:otherwise> 結(jié)合,來表達(dá)多重條件測試!

語法

<xsl:if
test="expression">

<!-- Content: template -->

</xsl:if>

屬性

屬性 描述
test expression 必需。規(guī)定要測試的條件。

實(shí)例

例子 1

當(dāng) CD 的價(jià)格高于 10 時(shí),選取 title 和 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">
      <xsl:if test="price &gt; 10">
        <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>

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

例子 2

顯示每個(gè) CD 的標(biāo)題。如果不是最后一個(gè)或倒數(shù)第二個(gè) CD,則在每個(gè) CD-title 間插入 ", "。如果是最后一個(gè) CD,則在標(biāo)題后添加 "!"。如果是倒數(shù)第二個(gè) CD,則在其后添加 ", and ":

<?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>
    <p>Titles:
    <xsl:for-each select="catalog/cd">
      <xsl:value-of select="title"/>
      <xsl:if test="position()!=last()">
        <xsl:text>, </xsl:text>
      </xsl:if>
      <xsl:if test="position()=last()-1">
        <xsl:text> and </xsl:text>
      </xsl:if>
      <xsl:if test="position()=last()">
        <xsl:text>!</xsl:text>
      </xsl:if>
    </xsl:for-each>
    </p>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>