`<xsl:for-each>` iterates over every node selected by its `select` attribute and processes its body for each node.
The `select` attribute contains the XPath expression that returns the node set to iterate over.
During each iteration, the context changes so that `.` represents the node currently being processed.
You can put one or more `<xsl:sort>` elements as the first children of `<xsl:for-each>` to sort the selected node set.
If the node set is empty, the body of `<xsl:for-each>` is not executed and nothing is output.
`position()` returns the 1‑based position of the current node within the selected node set.
`<xsl:for-each>` performs an explicit loop that can reduce reusability, whereas `<xsl:apply-templates>` relies on template matching and can be more flexible.