XSLT <choose>
<xsl:choose> elementi bir nechta shartli tekshiruvlarni ifodalash uchun <xsl:when> va <xsl:otherwise> bilan birgalikda ishlatiladi.
<xsl:choose> elementi
Sintaksis
<xsl:choose>
<xsl:when test="expression">
... some output ...
</xsl:when>
<xsl:otherwise>
... some output ....
</xsl:otherwise>
</xsl:choose>Choose shartini qayerga joylashtirish kerak
XML faylga nisbatan bir nechta shartli tekshiruv qo‘yish uchun XSL faylga <xsl:choose>, <xsl:when> va <xsl:otherwise> elementlarini qo‘shing:
Misol
<?xml version="1.0" encoding="UTF-8"?>
<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>
O‘zingiz sinab ko‘ring »
Yuqoridagi kod CD narxi 10 dan yuqori BO‘LGANDA "Artist" ustuniga pushti fon rangini (background-color) qo‘shadi.
Yana bir misol
Mana ikkita <xsl:when> elementini o‘z ichiga olgan yana bir misol:
Misol
<?xml version="1.0" encoding="UTF-8"?>
<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:when test="price > 9">
<td bgcolor="#cccccc">
<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>
O‘zingiz sinab ko‘ring »
Yuqoridagi kod CD narxi 10 dan yuqori BO‘LGANDA "Artist" ustuniga pushti fon rangini, CD narxi 9 dan yuqori va 10 dan kichik yoki unga teng BO‘LGANDA esa kulrang fon rangini qo‘shadi.
W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!
