Web Hosting Talk







View Full Version : XML -> HTML using XSLT with embedded HTML


shawn_t
04-29-2005, 09:56 PM
How can I get embedded HTML commands to work properly? For example, if I have the following XML file:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>

<Hotel>
<Amenity>
<table border="4">
<tr>
<td>
<b>Complimentary intro to SCUBA</b>
</td>
</tr>
</table>
</Amenity>
</Hotel>


and the following XSLT file:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!-- TEST.XSL -->
<xsl:stylesheet version="1.0">
<xsl:output method="html" />

<!-- XML root node template -->
<xsl:template match="/">
<html>
<head>
<title>Test XML->XHTML using XSLT</title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>

<!-- <Hotel> node template -->
<xsl:template match="Hotel">
<xsl:value-of select="Amenity" />
</xsl:template>

</xsl:stylesheet>
I would expect the resulting page to display the table defined in the Amenties field of the XML file, but I only get the text...

Ultimately, I would like to allow the client to type in malformed HTML that may not be valid in the XML file and have it also work. For example, an XML file like this:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>

<Hotel>
<Amenity>
<![CDATA[
Complimentary intro to SCUBA
<br>
<br>
<center><img src='ll_logo.gif'></center>
]]>
</Amenity>
</Hotel>

where both the <br> and the <img> tags are not properly terminated and would ordinarily cause errors in the XML if not for the CDATA tags. Is there a way for XSLT to output the contents of the CDATA tags and have it execute as real HTML instead of &lt; conversions?