ASP和XSL编码的问题

时间:2012-10-17 18:54:42

标签: xml xslt asp-classic

我正在通过经典ASP解析我的XML和XSL。 (这就是服务器可以运行的内容)我的XML和XSL文件被编码为UTF-8,但在解析时,它们转向UTF-16。这导致我的法语字符被错误地表示。

ASP代码:

'Load XML
Set URL_xml = Server.CreateObject("MSXML2.DomDocument.3.0")
URL_xml.async = false
URL_xml.SetProperty "SelectionLanguage", "XPath"
URL_xml.preserveWhiteSpace = True
URL_xml.load(Server.MapPath("xml/1_branches.xml"))
'Load XSL
Dim URL_xsl : Set URL_xsl = CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
URL_xsl.async = false
URL_xsl.load(Server.MapPath("xsl/default.xsl"))

Dim xslTemplate : Set xslTemplate = CreateObject("MSXML2.XSLTemplate.3.0")
xslTemplate.stylesheet = URL_xsl

Dim processor : Set processor = xslTemplate.createProcessor()
processor.addParameter "auth", cookie_auth
processor.addParameter "user_name", cookie_user_name
processor.input = URL_xml
processor.transform()

strTrans = processor.output
strFolder = strFolder & strFolders & strTrans

XML代码:

<?xml version="1.0" encoding="utf-8"?>
<root>
  <branches>
    <branch>Audit and Evaluation</branch>
    <folder>ae-ve</folder>
    <program></program>
    <section>About EC</section>
  </branches>
</root>

XSL代码:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output encoding="utf-8"  omit-xml-declaration="yes" method="html" indent="yes" ></xsl:output>
    <xsl:param name="auth"/>
    <xsl:param name="user_name"/>
    <xsl:template match="/">
        <xsl:if test="$auth = 'Super'">
            <p>There are <xsl:value-of select="count(root/branches)"/> individual folders.</p>
            <xsl:for-each select="root/branches">
                <xsl:variable name="folder" select="folder" />
                <fieldset><legend><strong><a href="url_list.asp?fldr={$folder}.xml"><xsl:value-of select="folder"/></a></strong></legend><!--h3 class="folder"><a href="url_list.asp?fldr={$folder}.xml"><xsl:value-of select="folder"/></a></h3-->
                <p class='details'><strong>Com Advisor: </strong>
                <xsl:for-each select="./people/person[@resp = 'com']">
                    <xsl:value-of select="."/>, 
                </xsl:for-each><br />
                <strong>Branch: </strong><xsl:value-of select="branch"/><br />
                <strong>Folder: </strong><xsl:value-of select="folder"/><br />
                <strong>Program: </strong><xsl:value-of select="program"/><br />
                <strong>Section: </strong><xsl:value-of select="section"/></p>
        </xsl:for-each>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

我现在一直在与此斗争。我在这里找到了一些好的建议,但大多数解决方案都会导致通过流保存文件。我需要将XSl的输出作为字符串变量,以便在文档中进一步使用。

1 个答案:

答案 0 :(得分:1)

要确保您的处理页面是UTF-8(并且您没有使用网络服务器默认代码页),您可以为您的网页设置代码页,如下所示:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<%
Response.CodePage = 65001
%>

可选:如果要将这些字符输出到浏览器(这里似乎不是这种情况),您也可以按如下方式设置输出编码:

<%
Response.Charset= "utf-8"
%>