XSLT <xsl:for-each>
❮ XSLT Element ရည်ညွှန်းချက်
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
<xsl:for-each> ဒြပ်စင်သည် သတ်မှတ်ထားသော node set တစ်ခုတွင် node တစ်ခုစီမှတဆင့် လှည့်ပတ်နေပါသည်။
အထားအသို
<xsl:for-each
select="expression">
<!-- Content -->
</xsl:for-each>
ဂုဏ်တော်
Attribute | Value | Description |
---|---|---|
select | expression | Required. An XPath expression that specifies which node set to be processed. |
ဥပမာများ
အောက်ပါဥပမာသည် cd ဒြပ်စင်တစ်ခုစီကို စီဒီတစ်ခုစီအတွက် ခေါင်းစဉ်ကိုထုတ်ပေးသည်-
ဥပမာ
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<div>
<xsl:for-each select="catalog/cd">
<p><xsl:value-of select="title" /></p>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
အောက်ဖော်ပြပါ ဥပမာသည် စီဒီဒြပ်စင်တစ်ခုစီကို လှည့်ပတ်ပြီး cd တစ်ခုစီအတွက် ခေါင်းစဉ်နှင့် အနုပညာရှင်ထံမှ တန်ဖိုးများပါသည့် ဇယားအတန်းတစ်ခုကို ဖန်တီးသည်-
ဥပမာ
<?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>
<h1>Music Collection:</h1>
<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>
❮ XSLT Element ရည်ညွှန်းချက်