Latest web development tutorials

XSLT <xsl: for-each> element

XSLT Elements Reference Manual XSLT Elements Reference Manual

Definition and Usage

<Xsl: for-each> element can cycle through each node of the specified node in the cluster.


grammar

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

Attributes

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


Examples

The following example loops through each cd element, and the output of each cd wrote:

Examples

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

try it"

The following example loops through each cd element and create a table shows each cd's title and artist:

Examples

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

try it"


XSLT Elements Reference Manual XSLT Elements Reference Manual