IE misreading UTF-8 in img src URL generated with XSLT



In my Windows desktop application, I generate an HTML report locally using XML and XSL. The report contains local images. Only Internet Explorer is supported for viewing the report.

If an image URL in this report contains UTF-8 characters, the image is not displayed in IE versions 9-11 (but Firefox is able to display it). In this case, the image URL in IE shows a sequence of latin characters in place of one UTF-8 character. For e.g., á (a with acute, represented as "%C3%A1" in UTF8) gets replaced with á. UTF-8 characters elsewhere in the report, including the img alt text, are displayed properly. Minimal XML and XSL for reproducing the issue:

XML:



<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="IE-issue.xsl"?>
<Image>C:/Temp/á_MyImage.jpg</Image>


XSL:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:html="http://ift.tt/qQdaDR"
xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output method="html" version="4.0" indent="yes" encoding="utf-8" omit-xml-declaration="yes"/>
<xsl:template match="Image">
<html>
<head>
<h3>á Heading</h3>
</head>
<body>
<xsl:element name="img">
<xsl:attribute name="src">
file:///<xsl:value-of select="."/>
</xsl:attribute>
<xsl:attribute name="alt">
file:///<xsl:value-of select="."/>
</xsl:attribute>
<xsl:attribute name="width">
400
</xsl:attribute>
<xsl:attribute name="height">
400
</xsl:attribute>
</xsl:element>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


The image path in this case is shown as "http://file/C:/Temp/á_MyImage.jpg" in IE. IE screenshot:


IE screenshot


Note that in the DOM Explorer, the path is shown as " file:///C:/Temp/%C3%A1_MyImage.jpg". Also, the alt text displays the UTF-8 correctly.


On searching, found an encoding problem description similar to this:

http://ift.tt/1hquc0H

It gives a couple of causes, but they are not applicable in my case.


Any ideas on how to resolve or work around this issue?


No comments:

Post a Comment