YouTip LogoYouTip

El For Each

XSLT <xsl:for-each> Element | Rookie Tutorial

Rookie Tutorial

XSLT <xsl:for-each> Element

XSLT Element Reference Manual

Definition and Usage

The <xsl:for-each> element loops through each node in the specified node set.

Syntax

<xsl:for-each select="expression">

</xsl:for-each>

Attributes

Attribute Value Description
select expression Required. An XPath expression that specifies the node set to be processed.

Example

The following example loops through each <cd> element and writes each <cd> to the output:


<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 yourself Β»

The following example loops through each <cd> element and creates a table to display the title and artist of each <cd>:


<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 yourself Β»

XSLT Element Reference Manual

XSLT Examples

XSLT Functions

Byte Ark Coding Plan

Supports mainstream large models such as Doubao, GLM, DeepSeek, Kimi, MiniMax, official supply stable and reliable.

Β₯9.9 / month

Immediately open

iflytek Star Coding Plan

Includes free model call quota, DeepSeek, GLM, Kimi, MiniMax, one-stop experience and deployment platform.

Β₯3.9 / month

Immediately open

Share Notes

Category Navigation

  • Python / Data Science
  • AI / Intelligent Development
  • Front-end Development
  • Back-end Development
  • Database
  • Mobile Development
  • DevOps / Engineering
  • Programming Language
  • Computer Fundamentals
  • XML / Web Service
  • .NET
  • Website Construction
← El IfEl Copy Of β†’