when
XSLT <xsl:when> elementi
❮ To‘liq XSLT elementlari ma’lumotnomasi
Ta’rif va qo‘llanilishi
<xsl:when> elementi <xsl:choose> elementi uchun amalni belgilashda ishlatiladi. <xsl:when> elementi ifodani hisoblaydi va agar u true qaytarsa, amal bajariladi.
Eslatma: <xsl:when> elementi bir nechta shartli tekshiruvlarni ifodalash uchun <xsl:choose> va <xsl:otherwise> bilan birgalikda ishlatiladi.
Sintaksis
<xsl:when
test="boolean-expression">
<!-- Content: template -->
</xsl:when>Atributlar
| Atribut | Qiymat | Tavsif |
|---|---|---|
| test | boolean-expression | Majburiy. Tekshiriladigan Boolean ifodani belgilaydi |
1-misol
Quyidagi kod cd narxi 10 dan yuqori BO‘LGANDA artist ustuniga pushti fon rangini (background-color) qo‘shadi.
<?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>XML faylni ko‘rish, XSL faylni ko‘rish va Natijani ko‘rish.
2-misol
"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>❮ To‘liq XSLT elementlari ma’lumotnomasi
W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!
