XSLT <xsl:when> အအုပ်
အဆိုပါ အခြေအနေ နှင့် အသုံးပြုခြင်း
<xsl:when> အအုပ် သည် <xsl:choose> အအုပ် အတွက် သတ်မှတ်ထားသော လုပ်ခြင်းကို အဆိုပါ:
<xsl:when> အအုပ် သည် အရိုက် ကို စစ်ဆေးပြီး true ပါက သတ်မှတ်ထားသော လုပ်ခြင်းကို အဆိုပါ:
ဖော်ပြ:<xsl:when> အအုပ် သည် <xsl:choose> အအုပ် နှင့် <xsl:otherwise> အအုပ် ကို ပေါင်းစပ်ထားသော အခြေအနေများ စစ်ဆေးပါ:
အက္ခရာ
<xsl:when test="boolean-expression"> <!-- Content: template --> </xsl:when>
အခြေအနေ
အခြေအနေ | အရေးအချင်း | ဖော်ပြ |
---|---|---|
test | boolean-expression | လိုအပ်သည်။ စစ်ဆေးသည့် ဘာလိုသည်ကို သတ်မှတ်ပါ: |
အကျိုးသတ္တု
အမှတ် 1
အောက်ပါ ကြောက်ချက် သည် cd မှ price အား 10 ထက် မြင့်မှု ဖြစ်လျှင် artist စာရင်းတွင် ပန်းပြားကြီး အကြောင်းအရာ အရေးသားသည့် အပြင်ပိုင်းကို အသုံးပြုပါ:
<?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>
XML ဖိုင် ကြည့်ပါ,XSL ဖိုင် ကြည့်ပါ,ရလဒ် ကြည့်ပါ.
အကြောင်းကျည်း 2
အမည် "color" ဟု ခေါ်သည့် အလိုရှိသော အဘာသာ တစ်ခု ပြောဆိုခဲ့သည်။ အဘာသာ သည် အရာသစ် အခြေခံ အကွက်၏ color အခြေခံ အချက်အလက် သဘော ဖြင့် အသုံးပြုသည်။ အရာသစ် အခြေခံ အကွက်၏ color အခြေခံ အချက်အလက် မရှိ လျှင် "color" အဘာသာ သည် "green" ဖြစ်လိမ့်မည်
<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>