XSLT <xsl:when>
❮ XSLT ဒြပ်စင် အကိုးအကားကို အပြီးသတ်ပါ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
<xsl:when> ဒြပ်စင်ကို <xsl:choose> ဒြပ်စင်အတွက် လုပ်ဆောင်ချက်တစ်ခုကို သတ်မှတ်ရန် အသုံးပြုပါသည်။ <xsl:when> ဒြပ်စင်သည် စကားရပ်တစ်ခုအား အကဲဖြတ်ပြီး အမှန်အတိုင်း ပြန်ဖြစ်သွားပါက လုပ်ဆောင်ချက်တစ်ခု လုပ်ဆောင်သည်။
မှတ်ချက်- အခြေအနေဆိုင်ရာ စမ်းသပ်မှုများစွာကို ဖော်ပြရန်အတွက် <xsl:when> ဒြပ်စင်အား <xsl:choose> နှင့် <xsl:otherwise> တို့နှင့် တွဲဖက်အသုံးပြုပါသည်။
အထားအသို
<xsl:when
test="boolean-expression">
<!-- Content: template -->
</xsl:when>
ဂုဏ်တော်
Attribute | Value | Description |
---|---|---|
test | boolean-expression | Required. Specifies a Boolean expression to be tested |
ဥပမာ ၁
cd ၏စျေးနှုန်းသည် 10 ထက်ပိုမိုသောအခါတွင်အောက်ပါကုဒ်သည်ပန်းရောင်နောက်ခံအရောင်ကိုအနုပညာရှင်ကော်လံတွင်ထည့်လိမ့်မည်။
<?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 ဖိုင်ကို ကြည့်ပါ ၊ XSL ဖိုင်ကို ကြည့်ပါ ၊ ရလဒ်ကိုကြည့်ရှုပါ ။
ဥပမာ ၂
"အရောင်" အမည်ရှိ ကိန်းရှင်တစ်ခုကို ကြေညာပါ။ ၎င်း၏တန်ဖိုးကို လက်ရှိဒြပ်စင်၏ အရောင်အရည်အသွေးအဖြစ် သတ်မှတ်ပါ။ လက်ရှိဒြပ်စင်တွင် အရောင်ရည်ညွှန်းချက်မရှိပါက၊ "အရောင်" ၏တန်ဖိုးသည် "အစိမ်းရောင်" ဖြစ်လိမ့်မည်-
<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 ဒြပ်စင် အကိုးအကားကို အပြီးသတ်ပါ။