[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Problem with Chinese (Solution)

Subject: Problem with Chinese (Solution)
From: "Shaun Bliss" <sb@xxxxxxxx>
Date: Wed, 8 Aug 2001 13:32:09 +0800
msxml chinese

Thanks to all who responded.  I have now fixed the problem and I will now
show how for others who may experience similar problems.

I was connecting to the web server using XMLHTTP, using the following

    // Format post URL
    var postUrl = webRoot + "/" + "xgetnihao.asp";

    // Create request xml document from passed xml
    xmlRequestDoc = new ActiveXObject("MSXML2.DOMDocument");
    xmlRequestDoc.async = 0;

    // Send xml object to the post URL
    xmlPostObject = new ActiveXObject("Microsoft.XMLHTTP");
    xmlPostObject.Open("POST", postUrl , false);

    // Get response object
    var xmlResponseDoc = new ActiveXObject("MSXML2.DOMDocument");
    xmlResponseDoc.async = 0;

    // Create stylesheet object
    var xslFile = "nihao.xsl";
    var xslDoc = new ActiveXObject("MSXML2.DOMDocument");
    xslDoc.async = 0;

    // Apply stylesheet to xml
    var outputHtml = xmlResponseDoc.transformNode(xslDoc);

    // Output result

This works great for standard encodings, but it will never work for
encodings like Chinese (GB2312).

The offending line which breaks it is:


The responseText attibute will always give some other encoding and
corrupt the data.  So you should use:


Note that I have changed 2 things here.  First to responseXML,
second the loadXML to just load.

Ok, so you do all that and it STILL doesn't work !!  So, next you
need to go to the ASP page which is generating your beautiful XML
and insert the following line of code:

       Response.contentType = "text/xml";

Of course, all of this is useless unless the ASP page generating
your XML does not start with:

       <?xml version="1.0" encoding="GB2312" ?>

Ok, so just to complete the full Chinese example you can use
this ASP page to test some of this code (called "xgetnihao.asp")

  <%@ Language="JavaScript" %>
  Response.contentType = "text/xml";
  var xml = "<?xml version=\"1.0\" encoding=\"GB2312\" ?>";
  xml += "<TestChinese>";
  xml += "你好";
  xml += "</TestChinese>";

An xsl stylesheet follows (called  "nihao.xsl"):

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
<xsl:output encoding="GB2312"/>
    <xsl:template match="/">
      <xsl:value-of select="/TestChinese" />

You can test the above code it should work.

However !!!  I did notice one interesting undesirable "feature" in the
MSXML.  If you put in some <HEAD></HEAD> tags into the
above XSL, then your output HTML contains the following by

  <META http-equiv="Content-Type" content="text/html; charset=UTF-16">

Maybe this is what MSXML thinks the closest thing to GB2312 is.
The bad thing is that the IE5.5 browser doesn't know how to Auto-Select
the GB2312 encoding when this is present.  This might be considered a
bug.  If you do not include HEAD tags, no content-type meta appears
and the GB2312 encoding is correctly auto-detected.

The above solution is partly in thanks to the following articles which
I merged and fiddled with to get the answer !


Hope this helps somebody, now I can get back to work !

ps.  I can confirm, the localized version of MSXML3.0 for Chinese
just shows all the error messages in Chinese, you don't need it to
make the code work.

pps.  I'm still in Side-by-side mode !!

Shaun Bliss (sb@xxxxxxxx)
Techical Architect, Paisley Crawford Ltd., Australia. (web site pending)
http://www.blissweb.com/   (personal)

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.