XSLT <xsl:choose>
❮ XSLT Element ရည်ညွှန်းချက်
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
အခြေအနေဆိုင်ရာ စမ်းသပ်မှုများစွာကို ဖော်ပြရန်အတွက် <xsl:choose> ဒြပ်စင်အား <xsl:when> နှင့် <xsl:otherwise> တို့နှင့် တွဲဖက်အသုံးပြုပါသည်။
<xsl:when> မဟုတ်ပါက၊ <xsl:otherwise> ၏ အကြောင်းအရာကို လုပ်ဆောင်ပါသည်။
<xsl:when> မဟုတ်ပါက အမှန်ဖြစ်ပြီး <xsl:otherwise> ဒြပ်စင်မရှိပါက မည်သည့်အရာကိုမျှ ဖန်တီးမည်မဟုတ်ပါ။
အကြံပြုချက်- ရိုးရှင်းသော အခြေအနေအရ စမ်းသပ်ခြင်းအတွက်၊ ၎င်းအစား <xsl:if> ဒြပ်စင်ကို အသုံးပြုပါ။
အထားအသို
<xsl:choose>
<!-- Content:(xsl:when+,xsl:otherwise?) -->
</xsl:choose>
ဂုဏ်တော်
တစ်ခုမှ
ဥပမာများ
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>
"အရောင်" အမည်ရှိ ကိန်းရှင်တစ်ခုကို ကြေညာပါ။ ၎င်း၏တန်ဖိုးကို လက်ရှိဒြပ်စင်၏ အရောင်အရည်အသွေးအဖြစ် သတ်မှတ်ပါ။ လက်ရှိဒြပ်စင်တွင် အရောင်ရည်ညွှန်းချက်မရှိပါက၊ "အရောင်" ၏တန်ဖိုးသည် "အစိမ်းရောင်" ဖြစ်လိမ့်မည်-
<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 Element ရည်ညွှန်းချက်