<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

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

      [摘要]七. XSL 的控制語句1.條件語句if...thenXSL同樣還有條件語句(呵呵~~好厲害吧,象程序語言一樣)。具體的語法是增加一個xsl:if元素,類似這樣<xsl:if match=".[ARTIST='Bob Dylan']">... som...
      七. 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>





      日韩精品一区二区三区高清