'******************************************* ' 说明:使用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 |