XSLT <xsl:for-each> အစိတ်အပျက်

အသုံးချက် နှင့် အမှုန်

<xsl:for-each> အရာတွေ ကို ခွဲစိတ်ထားသော အကိုရိုက်အချက်အလက်များတွင် ခွဲစိတ်ထားသော အချက်အလက်တစ်ခုခုကို ခွဲစိတ်ပြီး အသုံးပြုသည်。

အပြောအဆ

<xsl:for-each
select="expression">
  <!-- Content:(xsl:sort*,template) -->
</xsl:for-each>

attribute

attribute value ဖော်ပြ
select expression ကိစ္စကျသည်။ ဖြည့်ဆည်းပြီး အသုံးပြုသော အကိုရိုက်အချက်အလက်များ。

အကျိုးသတ္တု

လောက် 1

ခွဲစိတ်ပြီး ခုနစ်ထပ် "cd" အရာတွေကို ခွဲစိတ်ပြီး ခုနစ်ထပ် title နှင့် artist ကို <xsl:value-of> ကို အသုံးပြု၍ အထုတ်ပေးသည်:

<?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>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

XML အကွက် ကြည့်တော်မူ,XSL အကွက် ကြည့်တော်မူ,ရလဒ် ကြည့်တော်မူ.

လောက် 2

ခွဲစိတ်ပြီး ခုနစ်ထပ် "cd" အရာတွေကို ခွဲစိတ်ပြီး ခုနစ်ထပ် title နှင့် artist ကို <xsl:value-of> ကို အသုံးပြု၍ အထုတ်ပေးသည် (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">
      <xsl:sort select="artist"/>
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

XML အကွက် ကြည့်တော်မူ,XSL အကွက် ကြည့်တော်မူ,ရလဒ် ကြည့်တော်မူ.