Followup 80dd016: avoid using XMLSerializer when not absolutely necessary

Because XMLSerializer is broken in Firefox: it URL-encodes hrefs.

Also move brokenness detection out of transformAttributes and into
parse/serializeXhtml.

Change-Id: I917944a16786040c57969c611f82192de29ee57b
(cherry picked from commit a9c15e4f73d303a4619bcf264692c7799f37f8b9)