【问题标题】:Issues with ASP and XSL EncodingASP 和 XSL 编码问题
【发布时间】:2012-10-17 18:54:42
【问题描述】:

我正在通过经典 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 的输出作为字符串变量在文档中进一步使用。

【问题讨论】:

  • 您没有显示它,但您的 asp 页面是否也设置为 UTF-8?例如像这样
  • 不,但我现在就试试。谢谢。
  • AardVark71 你是个天才。非常感谢。
  • 很高兴它有帮助。由于它很有用,我也会将其作为答案发布。

标签: xml xslt asp-classic


【解决方案1】:

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

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

或

<%
Response.CodePage = 65001
%>

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-11
    • 2011-04-12
    • 2014-03-12
    • 2010-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多