Introduce ForeachNode and ForeachNodeSorted.

Allows looping over all nodes under a particular node, calling a callback
with the node name and node as arguments foreach node.

Rename ForeachSorted to ForeachSortedVal.