Here is a tutorial on how to use mod_proxy_html to edit the links on a webpage ( the content). You might be able to apply this modify the html you want.
UPDATE: Are you sure you want to go this route? I think Apache is meant to serve content, not create it. This would probably go in the view part of a MVC framework. The reason I wouldn't recommend this is you are breaking the rule of modularity. Your web application will be intertwined with the application that serversserver it, complicating future upgrades, moves, etc.