_xml examples of coding problems in the server-side XSLT process

Source: Internet
Author: User
Tags local time xsl xsl file xslt
Recently, and Apple peel in the discussion optimization Weather for the Google earth use XSLT to transform the XML data problem, then must use the conversion engine, presumably the process is to the XML file and XSLT files are reproduced into memory with the DOM engine to convert to the we want to HTML (in my case, to generate the KML file). This conversion process is divided between the client and the server side, because the client's browser needs the user's browsers to fully support XML, but not all of the user's browser is now supported (IE5, IE4, etc.), so the conversion of the service side is ideal.
XML file Form:

<?xml version= "1.0" encoding= "UTF-8"?>
<weather ver= "2.0" >
<loc id= "CHXX0101" >[...]
</loc>
<cc>[...]
</cc>
<dayf>
<lsup>10/28/06 11:16 AM Local time</lsup>
<day d= "0" t= "Saturday" dt= "Oct" >[...]
</day>
<day d= "1" t= "Sunday" dt= "Oct" >[...]
</day>
</dayf>
</weather>
XSLT file form (content partially omitted):

<?xml version= "1.0" encoding= "UTF-8"?>
<xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" >
<xsl:output method= "xml" version= "1.0" encoding= "UTF-8" indent= "yes"/>
<xsl:template match= "/" >[...]
</xsl:stylesheet>

I started the conversion code, with the ASP+JAVASCIRPT:

======== output type and stream encoding ==========================
Response.ContentType = "Application/vnd.google-earth.kml+xml";
Response.Charset = "UTF-8";
===== gets and loads the remote XML file ==========================
var oxhy = Server.CreateObject ("MSXML2.") XMLHTTP ");
var url = http://www.dnxh.cn/ge/CHXX0101.xml;
Oxhy.open ("Get", url,false);
Oxhy.send ();
var oxd = Server.CreateObject ("MSXML2.") DOMDocument ");
Oxd.loadxml (Oxhy.responsetext);
= = = Load xsl file =========================
var xsl = Server.CreateObject ("Microsoft.XMLDOM");
Xsl.async = false;
Xsl.load (Server.MapPath ("gew.xsl"));
Conversion of File = = = ====================
Response.Write (Oxd.transformnode (XSL));
Logically this should not be the problem of coding, because the declaration of the location of the code is declared. But there was a problem. The initial declaration of the output KML file is always
<?xml version= "1.0" encoding= "UTF-16"?>
The test found no problem with XML and XSLT two source files, and the problem was in the conversion engine in the ASP code, and later in the RE: [XSL] Problem with Chinese (Solution) This article probably found the cause, which says the engine transform Node is generated a string, and on the Win32 platform always UTF-16 to handle the string, and then we use this string to generate KML file, the result can only be UTF-16.
     the solution is to use the  transformNodeToObject  engine. The File Conversion section is replaced with  oxd.transformnodetoobject ( xsl , response). The difference between the two methods is that the previous one was to generate a string variable, and the latter is to directly save the converted  XML  data to the specified node.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.