|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Perl workaround for XSLT escaped UTF-8 pass-thru t
Mike Brown wrote:
Your stylesheet is hard-coded to create the following element in the HTML output, after the <title>, even though the output encoding might not actually be UTF-8:
http://starling.ws/foo.html Further, since in your example you are invoking the transformation via an xml-stylesheet PI, rather than from script in an HTML document or separate msxml.dll-using code altogether (e.g. msxsl.exe), the browser is invoking MSXML in a manner that forces the output to be UTF-16 *regardless* of what encoding was asked for in xsl:output. I'm not sure what you mean by 'PI' but the rest makes sense. So I put this... <meta http-equiv="Content-Type"content="text/html; charset=UTF-8"> ...BEFORE the <title></title>. I went with UTF-8 versus UTF-16 to match your prior suggestion above...so that they agree one to the other. Alas, still no go. As an experiment I changed the delcaration to UTF-16 and had a peek with both MSIE and Mozilla but results were the same. So I put it back to UTF-8. You can see this if you have installed the "tools for viewing and validating XSL output" (or whatever they're calling it today) from the MSDN site.
Since this META comes first, the browser ignores the one that says UTF-8. This is good, because your HTML isn't UTF-8 encoded, it is UTF-16 encoded. The document's bytes have to be decoded into characters properly or you'll get a big nonsensical mess. So the UTF-16 bytes are mapped back into characters properly, and the markup is parsed and rendered appropriately.
If I put encoding="utf-8" in the xsl:output instruction, and invoke the transform without using the xml-stylesheet PI, such as via msxsl.exe, I can get actual UTF-8 output that contains a generated META that says UTF-8.
Now as for your other problem, I fail to see what the problem is with having encoded characters in the document. If the document is UTF-8 or UTF-16 encoded, there's no need to ever use a numeric character reference, so long as the document or delivery protocol properly declares the encoding. The browser will handle it just fine, as long as the user has not overridden the encoding (which, sadly, they are allowed to do).
I have observed this for a long time since many of my XHTML pages (hand coded not XSLT) from a year past are in Esperanto. That is why I lean toward numeric character references. If you really want numeric character references anyway, then why use UTF-8 or UTF-16 output? Output ASCII instead, and the serializer will take care of generating NCRs for you. No need to run the document through a perl script.
It's ironic that the document you are rendering attempts to explain some of these issues. Am regularly checking the HTML output against both MSIE 6 SP 1 under Win2K and on Mozilla 1.2.1 under NetBSD. Have observed, and still observe the encoding glitch...as if it fails to read the meta tag. This even after changing the xsl:output tag in the XSLT and moving the hard-coded meta tag above the title. But is only so with bare UTF-8. It does not seem to happen when I employ numeric character references. Some old browsers (notably Netscape 4.x) are horribly nonconformant with regard to encoding and how they interpret both entity references and numeric character references, but they're not something you should be putting too much effort into working around.
And at the bottom of the document, you tell people to switch to UTF-8, but changing the encoding (decoding, actually) is not an option in IE, when viewing browser-rendered XSLT output (i.e. when rendering an XML doc that contains an xml-stylesheet PI pointing to an XSLT stylesheet).
You might also be interested in this little snippet:
Respectfully, Gan -- Mistera Sturno - Rarest Extinct Bird <(+)__ Gan Uesli Starling
((__/)=- Kalamazoo, MI, USA
`||`
++ http://starling.usXSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








