0

I've been working on a XSLT Document. And when i do conversion, the special characters(quotes, double quotes etc...) are shown as a rhombus with a queastion mark in it. i'm using UTF-8 Encoding and Altova xml spy software, please let me know how can i fix it.

I Declared my encoding in the first line.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ntw="Number2Word.uri" exclude-result-prefixes="ntw">
    <xsl:output method="html"/>
    <xsl:strip-space elements="*"/>


    <xsl:variable name="ThisDocument" select="document('')"/>


    <xsl:template match="/">
        <xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE html>]]></xsl:text>

        <html>
            <head>
            <xsl:text disable-output-escaping="yes"><![CDATA[</meta>]]></xsl:text>
            <title>
                <xsl:value-of select="part/title"/>
            </title>
            <link rel="stylesheet" href="main.css" type="text/css"/>
            <xsl:text disable-output-escaping="yes"><![CDATA[</link>]]></xsl:text>
            </head>
            <body>
            <xsl:apply-templates select="part"/>

            <section class="tr_footnotes">
                <hr/>
                <xsl:apply-templates select="//footnote" mode="footnote"/>
            </section>
            </body>
        </html>

and as an alternative i also tried the below.

    <xsl:output method="html" encoding="utf-8"/>

but there is no change in result.

Thanks.

user2423959
  • 836
  • 1
  • 13
  • 27

1 Answers1

0

This is pretty horrible code. I don't know whether making it less horrible will fix the problem, but if I were given the task, my first action would be to clean it up.

Since you are using output method HTML, the closing tags for the meta and link elements are not needed, so just get rid of the ghastly disable-output-escaping code that generates them. The !DOCTYPE line is a bit trickier, since XSLT 2.0 doesn't support generation of HTML5 directly, however, you can find a cleaner solution that doesn't rely on disable-output-escaping here:

How to output <!DOCTYPE html> with XSLT

So back to your real problem: why doesn't the browser display the special characters correctly? The answer is that the encoding of the document is not what the browser thinks it is. I can't see immediately why that should be; one possibility is that you've done something to the document between generating it and sending it to the browser that changes the encoding; another possibility is that the HTTP headers are wrong.

Community
  • 1
  • 1
Michael Kay
  • 156,231
  • 11
  • 92
  • 164