pass correct DocumentContext when rewriting trees
use template config when rewriting a dynamic document