1

为了生成 HTML 报告,我试图在下面执行代码。该脚本在“xmlSource.transformNode(xmlXForm)”处引发错误。错误显示“样式表不包含文档元素”。

请帮忙。

Function ConvertToHTML(sResultPath)
    'sResultPath = "C:\DOCUME~1\user\LOCALS~1\Temp\TempResults\"
    sProductDir = "C:\Program Files\HP\QuickTest Professional\dat\"
    strOldText = "UTF-16"
    strNewText = "UTF-8"
    Const ForWriting = 2
    Set xmlSource = CreateObject("MSXML.DOMDocument")
    Set xmlXForm = CreateObject("MSXML.DOMDocument")

    xmlSource.validateOnParse = True
    xmlXForm.validateOnParse = True
    xmlSource.async = False
    xmlXForm.async = False

    xmlSource.Load sResultPath & "Report\Results.xml"
    xmlXForm.Load sProductDir & "PShort.xsl" 'if you want more details, then you can use PDetails.xsl
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set fso = CreateObject("Scripting.FileSystemObject")
    sHTMLPath = Replace(sResultPath & "Report\Results.xml", ".xml", ".html")
    Set file = fso.OpenTextFile(sHTMLPath, ForWriting, True)
    file.write xmlSource.transformNode(xmlXForm)
    file.Close

    fso.CopyFile sProductDir & "PResults.css", sResultPath & "Report\"


    Set file = Nothing
    Set fso = Nothing
    Set xmlXForm = Nothing
    Set xmlSource = Nothing

End Function

Call ConvertToHTML("H:\GB_Automation\Res1\")

谢谢巴维亚

4

1 回答 1

0

The error you are seeing typically indicates that the stylesheet is empty or nothing was loaded. Double-check that the file path of your XSL file is accurate. According to your code, you are trying to load the file from here:

C:\Program Files\HP\QuickTest Professional\dat\PShort.xsl

You stated that you are using "QTP 12", but the last version of QTP was v11. Starting with v11.50, it was renamed as Unified Functional Testing. Part of that rename means that the default installation folder is no longer under "QuickTest Professional".

I just checked my installation of UFT 12 on a 64-bit OS, and the path I have for the same file is:

C:\Program Files (x86)\HP\Unified Functional Testing\dat\PShort.xsl

For 32-bit OS, it would be:

C:\Program Files\HP\Unified Functional Testing\dat\PShort.xsl
于 2014-07-08T16:49:40.200 回答