XSLT <xsl:when> ÔªËØ
¶¨ÒåºÍÓ÷¨
<xsl:when> ÔªËØÓÃÓÚΪ <xsl:choose> ÔªËØ¹æ¶¨Ïà¹Ø¶¯×÷¡£
<xsl:when> ÔªËØ»á¼ÆËãÒ»¸ö±í´ïʽ£¬Èç¹û·µ»Ø true£¬ÔòÖ´Ðй涨µÄ¶¯×÷¡£
×¢ÊÍ£º<xsl:when> ÔªËØÌṩ¶à¸öÓë <xsl:choose> ÔªËØºÍ <xsl:otherwise> ÔªËØÓйصÄÌõ¼þ²âÊÔ¡£
Óï·¨
<xsl:when test="boolean-expression"> <!-- Content: template --> </xsl:when>
ÊôÐÔ
ÊôÐÔ | Öµ | ÃèÊö |
---|---|---|
test | boolean-expression | ±ØÐè¡£¹æ¶¨Òª²âÊԵIJ¼¶û±í´ïʽ¡£ |
ʵÀý
Àý×Ó 1
ÏÂÃæµÄ´úÂë»áÔÚ cd µÄ price ¸ßÓÚ 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>'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" µÄ±äÁ¿¡£°ÑËüµÄÖµ¸³¸øµ±Ç°ÔªËØµÄ color ÊôÐÔ¡£Èç¹ûµ±Ç°ÔªËØÃ»ÓÐ 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>