Using a web app as a templating engne in this way is a bit weird. I'd have used something you could automate with
ant, perhaps XSLT.
In any case, I guess you could set up a filter and a response wrapper that could write the resulting responses to the file system, and then have a script that traverses every page on the site.
Search for "filter" and "response wrapper" in the forum for previous discussions of their usage.