Rewrite the HTML XSLT upgrader

Comes with an extensive test suite.