XSLT <xsl:for-each>
❮XSLT要素リファレンス
定義と使用法
<xsl:for-each>要素は、指定されたノードセット内の各ノードをループします。
構文
<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要素をループして各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要素をループし、各cdのtitleとartistの値を使用してテーブル行を作成します。
例
<?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要素リファレンス