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 ထက် မြင့်မှာ သတ္တုသတ္တုရောင် အသားအရောင် အပြင်ဘက် အသုံးပြုခြင်း ပြုလုပ်သည့် ကြောက်လုံး:

<?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>