XSLT <xsl:choose> ÔªËØ

¶¨ÒåºÍÓ÷¨

<xsl:choose> ÔªËØÓë <xsl:when> ÒÔ¼° <xsl:otherwise> ÔªËØ½áºÏ£¬¿É±í´ï¶àÖØÌõ¼þ²âÊÔ¡£

Èç¹ûûÓÐ <xsl:when> ÊÇ true£¬Ôò´¦Àí <xsl:otherwise> µÄÄÚÈÝ¡£

Èç¹ûûÓÐ <xsl:when> ÊÇ true£¬ÇÒ²»´æÔÚ <xsl:otherwise> ÔªËØ£¬Ôò²»´´½¨ÈκÎÄÚÈÝ¡£

Ìáʾ£º¶ÔÓÚ¼òµ¥µÄÌõ¼þ²âÊÔ£¬ÇëʹÓà <xsl:if> ÔªËØÈ¡¶ø´úÖ®¡£

Óï·¨

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

ÊôÐÔ

None

ʵÀý

Àý×Ó 1

ÏÂÃæµÄ´úÂë»áÔÚ CD µÄ¼Û¸ñ¸ßÓÚ 10 ʱ£¬Ïò 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 Îļþ£¬²é¿´½á¹û¡£

Àý×Ó 2

ÉùÃ÷ÃûΪ "color" µÄ±äÁ¿¡£°ÑÕâ¸ö±äÁ¿µÄÖµ¸³Öµµ½ current ÔªËØµÄ color ÊôÐÔ¡£Èç¹û current ÔªËØÃ»ÓÐ 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>
VUE