8. Repetition with for-each

foreach -> 'for-each' node_set_XPath_expression '{' block_contents '}'

block_contents -> [ command | if | foreach ]*

XPath expression node_set_XPath_expression is evaluated as a node set, then for-each iterates over the nodes of this set, running block_contents at each iteration.

Inside block_contents, the context node is the current node of the node set iterated over. Example:

(: The context node is /html/body. :)

for-each .//p {
    (: Inside this for-each, the context-node is a p
       which is a descendant of body. :)

    remove-attribute("style");
}