Until today I was thinking that xslt functions have no side effects
(provided extensions are not considered).
It has turned out that this is not correct.
That changes the picture (at least for me).
Many possible optimizations are not safe.
It's not that bad. You just have to be careful in expressions where
nodes are created and the results of the expression rely on properties
related to the node ID. In practice that doesn't happen that often.