XSLT <xsl:choose> အရာ
- ပြီးခဲ့သော စာပေးအုပ် XSLT <if>
- နောက်ပိုင်း စာပေးအုပ် XSLT apply
XSLT <xsl:choose> အရာဝတ္တုက <xsl:when> နှင့် <xsl:otherwise> ကို ပေါင်းစပ်သုံးသည် တခုခုကို အခြား အခြေအနေအကြောင်း စစ်ဆေးရန် အသုံးပြုသည်。
<xsl:choose> အရာဝတ္တု
လိုဘ်း
<xsl:choose> <xsl:when test="expression"> ... ထုတ်လုပ်ခြင်း ... </xsl:when> <xsl:otherwise> ... ထုတ်လုပ်ခြင်း ... </xsl:otherwise> </xsl:choose>
အခြား အခြေအနေအကြောင်း ထပ်ပေါင်းရာ နေရာ
XML ဖိုင်တွင် အခြား အခြေအနေအကြောင်း စစ်ဆေးခြင်း ထပ်ပေါင်းရန် <xsl:choose>、<xsl:when> နှင့် <xsl:otherwise> ကို ထပ်ပေါင်းပါ
<?xml version="1.0" encoding="ISO-8859-1"?> <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>
ဒီ ကိုယ်ဝင်အချက်အလက်က အင်တာဒိုင်း ကို ၁၀ ထက် မြင့်မှာ ပန်းထိုးသော အမှတ်အသားများ ကို "Artist" စာရင်းတွင် ပန်းထိုးအသားအရောင်ကို ထပ်ပေါင်းပေးသည်。
အထက်ပါ ပြောင်းလဲသော ရလဒ် အသီးသီး အဖြစ် ပြောင်းလဲသည်။

ဒီ XML ဖိုင်ကို ကြည့်ပါ,ဒီ XSL ဖိုင်ကို ကြည့်ပါ,ရလဒ် ကို ကြည့်ရှုရန်。
ဒီအပြောင်းသတင်း
ဒီအပြောင်းသတင်းတွင် ၂ခုရှိသော <xsl:when> အရာဝတ္တုများပါဝင်သည်:
<?xml version="1.0" encoding="ISO-8859-1"?> <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>
ဤ ကြောင်းကြားချက် သည် CD သည် 10 ထက် မြင့်သော အခြေအနေမှာ "Artist" စာရင်း အရိုးများ အရောင် ပန်းပြား အရောင် အခြေအနေ ပြင်ဆင်ပြီး၊ CD သည် 9 ထက် မြင့် နှင့် 10 ထက် တူတွင် မဟုတ် နှင့် "Artist" စာရင်း အရိုးများ အခြေအနေ အရောင် အခြေအနေ ပြင်ဆင်ပြီး။
အထက်ပါ ပြောင်းလဲသော ရလဒ် အသီးသီး အဖြစ် ပြောင်းလဲသည်။

ဤ XML ဖိုင် ကို ကြည့်ရှုရန်,ဤ XSL ဖိုင် ကို ကြည့်ရှုရန်,ရလဒ် ကို ကြည့်ရှုရန်。
- ပြီးခဲ့သော စာပေးအုပ် XSLT <if>
- နောက်ပိုင်း စာပေးအုပ် XSLT apply