Latest web development tutorials

XSLTで<xsl:for-each>要素

XSLTの要素リファレンス・マニュアル XSLTの要素リファレンス・マニュアル

定義と使用法

で<xsl:for-each>要素のサイクルは、クラスタ内の指定したノードの各ノードを経由することができます。


文法

<xsl:for-each select="expression">
<!-- Content -->
</xsl:for-each>

プロパティ

属性 描述
select expression 必需。一个 XPath 表达式,规定被处理的节点集。


次の例では、各CD要素をループし、各CDの出力は書きました:

<?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="/">
<div>
<xsl:for-each select="catalog/cd">
<p><xsl:value-of select="title" /></p>
</xsl:for-each>
</div>
</xsl:template>

</xsl:stylesheet>

»をお試しください

次の例では、各CD要素をループし、テーブルを作成し、各CDのタイトルやアーティストを示しています。

<?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>
<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の要素リファレンス・マニュアル XSLTの要素リファレンス・マニュアル