Question

My problem is that my XML document contains snippets of XHTML within it and while passing it through an XSLT I would like it to render those snippets without mangling them.

I've tried wrapping the snippet in a CDATA but it doesn't work since less than and greater than are translated to < and > as opposed to being echoed directly.

What's the XSL required for doing this?

Was it helpful?

Solution

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

This is referred to as the "identity transformation" in the XSLT specification.

OTHER TIPS

I ran in that problem and the copy-of is certainly the easiest to use. The identity works, but that's 5 lines of code and you'd need to call such a template, not just define it as is in your XSLT document (otherwise you probably won't get what you expected in your output.)

My main problem actually was to copy the content of a tag, and not the tag itself. It's actually very easy to resolve but it took me a little time to figure it out (maybe because QtXmlPatterns crashes quite a bit!)

So, the following copies the tag named here and all of its children:

<xsl:copy-of select="this/tag/here"/>

But most often you do not want to do that because <here> is actually the container, in other words, it should not appear in the output. In that case you can simply do this:

<xsl:copy-of select="this/tag/here/*"/>

This copies all the children found in the tag named <here>.

Assuming your xhtml is in an element YYY

http://www.dpawson.co.uk/xsl/sect2/N1930.html explains options

xsl:copy-of

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top