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