XSLT script (save as a separate .xsl file and save content in a UTF-8 encoding format, not ANSI)<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output version="1.0" encoding="utf-8" indent="yes" /><xsl:strip-space elements="*"/> <!-- Identity Transform to copy all of doc as is --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <!-- replace accented character --> <xsl:template match="text()"> <xsl:value-of select="translate(., 'Ãàḗḯǿǘḉǹ', 'èaeioun')"/> </xsl:template></xsl:transform> VBA (其中后面的引用应指向newXML而不是objXML) Set objXML = New MSXML2.DOMDocumentobjXML.async = FalseobjXML.LoadXML (objHTTP.ResponseText)objXML.Save "C:\Users\Dan\Desktop\MySubOutput.xhtml"Set objXSL = New MSXML2.DOMDocumentobjXSL.async = FalseobjXSL.Load "C:\Path\To\XSLT\Script.xsl"' TRANSFORMING objXML to newXMLSet newXML = New MSXML2.DOMDocumentobjXML.transformNodeToObject objXSL, newXML' NOTICE newXML REFERENCESXmlNamespaces = "xmlns:doc='urn:ebay:apis:eBLBaseComponents'"newXML.setProperty "SelectionNamespaces", XmlNamespacesnewXML.setProperty "SelectionLanguage", "XPath"Dim xItemList As IXMLDOMNodeListSet xItemList = newXML.DocumentElement.SelectNodes("//doc:Transaction")... XSLT甚至可以作为VBA字符串而不是文件嵌入.确保使用双引号,并且使用objXSL.LoadXML代替objXSL.Load(就像使用http响应一样).而且之所以相似,是因为XSLT文件 是格式正确的XML文件,带有脚本指令!XSLT can even be embedded as a VBA string and not in a file. Be sure to escape double quotes and instead of objXSL.Load you would use objXSL.LoadXML (just as you did with http response). And the reason it is similar, is that XSLT files are well-formed XML files which carry scripting instructions! 这篇关于修复VBA中的XML编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 12:41