I think disable-output-escaping
is your best bet for this particular data with XSLT 1.0.
Even better would be to change how the source XML is being generated, if possible, to ensure that it is generating well-formed XML. But that can be difficult if you don't control how the HTML is constructed, or is just shifting the work to be done on input instead of output.
If someone forgets to close an element or does use valid HTML syntax that is not well-formed, such as <br>
or <img>
then the source XML would not be well-formed and could not parse. So, the "safe" way is to jam it into CDATA or escape the markup and put in as text()
. But then that becomes your problem to figure out how to turn it back into markup on the way out.
There are tools, such as tidy that can be used to parse HTML and ensure that it is well-formed.
If you know that it is well-formed, then make it actual xHTML in the <Text>
and then it will serialize properly without figuring out how to parse the string into XML or use tricks to serialize without escaping.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…