I have an XML file with all the nodes that contain information are in CDATA. These information are possibly formatted with some HTML tags, something like this:
<EventList>
<Text><![CDATA[<p>Some text <i>is</i> formatted! This is a character entity '</p>]]></Text>
<ShortText><![CDATA[Some other is only plain]]></ShortText>
<!-- others more -->
</EventList>
I want to transform this with XSLT in a (X)HTML page:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:output
method="html"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
media-type="application/xhtml+xml"
encoding="utf-8"
omit-xml-declaration="yes"
indent="no"
/>
<xsl:template match="Text">
<h2><xsl:copy-of select="text()"/></h2>
</xsl:template>
<xsl:template match="ShortText">
<div><xsl:copy-of select="."/></div>
</xsl:template>
</xsl:stylesheet>
But appling this transformation produce a strange behavior. The HTML tags I did put in the XSLT are parsed and interpreted correctly from the browser, but the tags inside the CDATA are stripped of the <
, >
and &
char, producing this output:
<h2>pSome text iis/i formatted! This is a character entity #39;/p</h2>
<div>Some other is only plain</div>
At first it looked something like an issue in the <xsl:output>
definition, but I'm still stuck on this. I've tried to use the shorthand XPath .
and the function text()
but the output it's the same.
Any suggestion is appreciated!