'******************************************* ' 說明:使用XSL文件格式化XML文件。 ' 作者:gwd 2002-11-05 ' 參數:strXmlFile -- Xml文件,路徑+文件名 ' strXslFile -- Xsl文件,路徑+文件名 ' 返回:成功 -- 格式化后的HTML字符串 ' 失敗 -- 自定義的錯誤信息 '******************************************* Function FormatXml(strXmlFile, strXslFile) Dim objXml, objXsl strXmlFile = Server.MapPath(strXmlFile) strXslFile = Server.MapPath(strXslFile) Set objXml = Server.CreateObject("MSXML2.DOMDocument") Set objXsl = Server.CreateObject("MSXML2.DOMDocument") objXML.Async = False If objXml.Load(strXmlFile) Then objXsl.Async = False objXsl.ValidateonParse = False If objXsl.Load(strXslFile) Then On Error Resume Next ' 捕獲transformNode方法的錯誤 FormatXml = objXml.transformNode(objXsl) If objXsl.parseError.errorCode <> 0 Then Response.Write "<br><hr>" Response.Write "Error Code: " & objXsl.parseError.errorCode Response.Write "<br>Error Reason: " & objXsl.parseError.reason Response.Write "<br>Error Line: " & objXsl.parseError.line FormatXml = "<span class=""alert"">格式化XML文件錯誤?。?span>" End If Else Response.Write "<br><hr>" Response.Write "Error Code: " & objXsl.parseError.errorCode Response.Write "<br>Error Reason: " & objXsl.parseError.reason Response.Write "<br>Error Line: " & objXsl.parseError.line FormatXml = "<span class=""alert"">裝載XSL文件錯誤!</span>" End If Else Response.Write "<br><hr>" Response.Write "Error Code: " & objXml.parseError.errorCode Response.Write "<br>Error Reason: " & objXml.parseError.reason Response.Write "<br>Error Line: " & objXml.parseError.line FormatXml = "<span class=""alert"">裝載XML文件錯誤?。?span>" End If Set objXsl = Nothing Set objXml = Nothing End Function |