Producing HTML from XML

Associate
Joined
15 May 2006
Posts
224
Hi,

I'm having a problem here converting an XML document into HTML using XSLT. The problem is that the XML document contains entity references for characters such as < which I really need converted into their character versions in the output document.

For example, part of the XML document might contain:

Code:
<description>this is some text. &lt;p;&gt And some more text</description>

In my HTML output I need this to be rendered as:

Code:
this is some text. <p> And some more text

Otherwise the browser (IE6 in this case) displays the characters <p> in the viewed document rather than the intended markup.

The output type for the XSLT is set to html. Using disable-output-escaping didn't make any difference either.

Can someone help before I pull the rest of my hair out? I'm fairly new to XSLT so could be missing something really simple.

Thanks,
Jim
 
Here's a copy of the XSLT:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes">
	<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>


	<xsl:template match="/">
		<html>
			<head>
			</head>
			<body>
				<table width="100%">
					<xsl:apply-templates/>
				</table>
			</body>
		</html>
	</xsl:template>

	<xsl:template match="channel">
		<table id="newsheadinginfo">
			<xsl:apply-templates/>
		</table>
	</xsl:template>

	<xsl:template match="channel/*">
		<tr class="headingitem">
			<td class="headingitemtitle">
				<xsl:value-of select="name()"/>
			</td>
			<td class="headingitemcontent">
				<xsl:value-of select="."/>
			</td>
		</tr>
	</xsl:template>


	<xsl:template match="channel/item">
		<table id="newsitem">
			<xsl:apply-templates/>
		</table>
	</xsl:template>


	<xsl:template match="channel/item/title">
		<th id="newsitemtitle" colspan="2">
			<xsl:value-of select="."/>
		</th>
	</xsl:template>

	[B]<xsl:template match="channel/item/description">
		<tr>
			<td  id="newsbody" colspan="2">
				<xsl:value-of disable-output-escaping="yes" select="."/>
			</td>
		</tr>
	</xsl:template>[/B]

	<xsl:template match="//channel/link">
		<tr>
			<td>News supplied by</td>
			<td>
				<xsl:value-of select="."/>
			</td>
		</tr>
	</xsl:template>

	<xsl:template match="link">
		<tr>
			<td>
				<xsl:value-of select="."/>
			</td>
		</tr>
	</xsl:template>


	<xsl:template match="guid">
	</xsl:template>


	<xsl:template match="item/pubDate">
		<tr id="itempublisheddate" align="left">
			<td>Published on</td>
			<td>
				<xsl:value-of select="."/>
			</td>
		</tr>
	</xsl:template>

</xsl:stylesheet>

And here's a sample of the problematic piece of XML:

Code:
			<description>Palm's Treo 680 and 700p smartphones are getting what BlackBerries and Windows-based smartphones, including Palm's Windows-based models themselves, have long enjoyed: push e-mail. 

&lt;P&gt;

On Thursday, Palm announced an update to Microsoft Exchange ActiveSync, the

It's from a free XML newsfeed. I'm trying to convert it from the XML to HTML so I can style it using CSS. Just an exercise to learn a bit about this stuff. I've indicated the bit in the XSLT that reads the <description> element in bold.

Thanks for any advice you can give me either on this problem or on other dodgy bits you might spot in my XSLT.

Jim
 
Back
Top Bottom