only for RuBoard |
xsl:for-each provides iterative looping over a node set to apply a template to each node in the node set. The xsl:for-each element contains a template that's applied to each node in the node set selected by the expression in the select attribute.
Attribute Name | Enforced | Description | Values |
---|---|---|---|
select | Required | An expression that evaluates to a node set | Expression |
Given the following XML instance document, links.xml :
<links> <link name="NewRiders.com" URL="http://www.newriders.com" /> <link name="Xmlandasp.net" URL="http://www.xmlandasp.net" /> <link name="MSDN Online Library" URL="http://msdn.microsoft.com/library" /> </links>
The following stylesheet selects the node list containing all link nodes. Each iteration applies the local template that outputs the name attribute and the <br/> tag:
<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:for-each select="links/link"> <xsl:value-of select="@name" /> <br /> </xsl:for-each> </xsl:template> </xsl:stylesheet>
This results in the following markup:
<?xml version="1.0" encoding="UTF-16"?> NewRiders.com<br />Xmlandasp.net<br />GotDotNet.com<br/>MSDN Online Library<br />
xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:for-each, xsl:if, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements
xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:sort, xsl:text, xsl:value-of, xsl:variable, output elements
only for RuBoard |