I spent longer on this than I should have, when the answer is so simple; I’m posting here to remind myself when it comes up again, and I hope the included keywords assist in anyone’s search for the same information.
The xsl:copy-of element can be used to insert a result tree fragment into the result tree, without first converting it to a string as xsl:value-of does
1) I’m assuming you have XHTML nested in your XML document, if you’re not well-formed, that’s your first problem to address. You can’t validate something you don’t restrict.
2) In your xsl:stylesheet, declare your intent to display HTML markup with:
<xsl:output method="html"/>
3) In your xsl:template, extract the XHTML with:
<xsl:copy-of select="nodeContainingHtml"/>
If you think you want to instead use output=”text” and CDATA to push your non-XHTML markup through, return to step 1.
4 thoughts on “Preserve HTML in XML with XSL”