I played a bit with making a unit test for this, see the attached file. This requires the ert2.el that comes with nXhtml and should be placed in the same subdir as nxhtmltest-suites.el.