choose
XSLT <xsl:choose> elementi
❮ XSLT elementlari ma’lumotnomasi
Ta’rif va qo‘llanilishi
<xsl:choose> elementi bir nechta shartli tekshiruvlarni ifodalash uchun <xsl:when> va <xsl:otherwise> bilan birgalikda ishlatiladi.
Agar hech bir <xsl:when> rost (true) bo‘lmasa, <xsl:otherwise> tarkibi qayta ishlanadi.
Agar hech bir <xsl:when> rost (true) bo‘lmasa va <xsl:otherwise> elementi mavjud bo‘lmasa, hech narsa yaratilmaydi.
Maslahat: Oddiy shartli tekshiruvlar uchun buning o‘rniga <xsl:if> elementidan foydalaning.
Sintaksis
<xsl:choose>
<!-- Content:(xsl:when+,xsl:otherwise?) -->
</xsl:choose>Atributlar
Yo‘q
Misollar
Quyidagi kod CD narxi 10 dan yuqori BO‘LGANDA artist ustuniga pushti fon rangini (background-color) qo‘shadi.
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 »
"color" nomli o‘zgaruvchini e’lon qiling. Uning qiymatini joriy elementning color atributiga o‘rnating. Agar joriy elementda color atributi bo‘lmasa, "color" qiymati "green" bo‘ladi:
<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>❮ XSLT elementlari ma’lumotnomasi
W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!
