Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML
IMCreator - Free Website Builder

XSLT <for-each> Element

The XSLT <xsl:for-each> element allows you to loop through multiple nodes that match the selection criteria. This in turn, enables you to retrieve data from these nodes.

For example, imagine if our XML file had two elements called "name" - each under the "tutorial" element. Like this:

Code

To extract data from both "name" elements, we can use <xsl:for-each> in conjunction with <xsl:value-of>.

<xsl:for-each> Example

Here, we use <xsl:for-each> to loop through each "name" element, and <xsl:value-of> to extract data from each node.

Note the value of the select attribute ("."). This expression specifies the current node. The <xsl:element name="br"/> element/attribute is there simply for readibility purposes - it provides a line break after each iteration.

Code

Enjoy this page?

  1. Link to this page (copy/paste into your own website or blog):
  2. Link to Quackit using one of these banner ads.

Thanks for supporting Quackit!