XSLT could have been the answer. But browsers are now dropping support for it.