Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quotation marks and Copyright symbol Transform to HTML 1

Status
Not open for further replies.

dseaver

IS-IT--Management
Jul 13, 2006
467
I get an XML back from a provider and I am transforming it into HTML to be displayed on a webpage. The problem is the provider uses the quotes and copyright symbol in the XML and they dont appear in the HTML for obvious reason. How can I check text parsed in the XSL template below to escape these characters so that they are displayed correctly on the page?

Code:
        <xsl:template match="text()">
		<xsl:value-of select="." />
	</xsl:template>
[/code\]
 
You might choose one of the two approaches.

[1] If I guess the locale Latin-1 is applicable to your audience and that it can handle all the special characters within the page other than copyright, in that case, you may specify the encoding in your output method. Like this, modulo other possible attributes.
[tt]
<xsl:eek:utput method="html" encoding="iso-8859-1" />
[/tt]
[2] Or, You might as well the default encoding utf-16 or setting utf-8. This is not necessarily related to the original xml document's encoding. But, in the transformed result, you add meta tag to notice the browser which charset it has to use to render the page. Such as this, detail as to where to put that line depending on your actual xsl document.
[tt]
<xsl:template match="/">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
[/tt]
Both are not 100%, rendering depends on many factors out of the control of the xml technology.
 
Perfect, option 1 did the trick!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top