This parses the legislation.gov.uk XML and turns it into well-formed, idiomatic HTML5.
This code is a complete, unmitigated disaster. The intention was to avoid accidentally missing out parts of the structure, but this makes it into a horrible, stateful mess.