In the XSLT process on the server side, Apple recently used XSLT to convert XML data when discussing and optimizing Weather For Google Earth. the conversion engine must be used here, the general process is to reload the XML and XSLT files to the memory and use the DOM engine to convert them to the HTML we want (I want to generate a KML file in this instance ). The conversion process is divided into the client and the server, because the client conversion requires the user's browser to fully support XML, but not all users' browsers currently support (IE5, IE4, etc.), so it is ideal for server-side conversion.
XML file format:
[...]
[...]
[...]
10/28/06 11:16 AM Local Time
[...]
[...]
XSLT file format (content omitted ):
[...]
The conversion code I started using ASP + export cirpt:
// ========= Output type and stream encoding ==================================== =
Response.ContentType = "application/vnd.google-earth.kml+xml"; Response.CharSet = "UTF-8" ;
// =======Obtain and load 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 the XSL file ============================
var xsl = Server.CreateObject("Microsoft.XMLDOM"); xsl.async = false; xsl.load(Server.MapPath("gew.xsl"));
// ======= File conversion ==========================
Response. Write (oXD. transformNode (xsl ));
It is reasonable to say that there should be no encoding problem, because the declaration of the encoding is declared. But something went wrong. The statement at the beginning of the output KML file is always
Test shows that there are no problems with the XML and XSLT source files, that is, the Problem lies in the conversion engine in ASP code, and then in RE: [xsl] Problem with Chinese (Solution) this article probably found the reason, here it is said that the engine transformNode is to generate a string, and on the win32 Platform is always to process the string with a UTF-16, then we use this string to generate the KML file, then the result can only be UTF-16.
The solution is to use the transformNodeToObject engine. Replace the file conversion part with oXD. transformNodeToObject (xsl, Response ). The difference between the two methods is that the first one generates a string variable, and the other is to directly save the converted XML data to the specified node.
The above is the detailed content of the solution to the encoding problem that occurs during the XSLT process on the server side. For more information, see other related articles in the first PHP community!