• 将XML转为HTML


    文章参考:http://dreamweaver.abang.com/od/html/a/xml2html3.htm

         http://www.w3school.com.cn/xml/xml_xsl.asp


    ParseXML2HTML.xsl:代码如下

     1 <?xml version="1.0" encoding="utf-8"?>                 
     2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     3     <xsl:output method="html" encoding="gb2312"/> 
     4     <xsl:template match="/"> 
     5         <html> 
     6             <body> 
     7                 <h2>未通过用例:</h2> 
     8                 <table border="0" cellspacing="4" width="900px"> 
     9                     <tr bgcolor="#FF2D2D" > 
    10                         <th align="center">Name</th> 
    11                         <th align="center">FailureType</th> 
    12                         <th align="center">Message</th> 
    13                         <!-- <th align="center">Location</th>  -->
    14                         <th align="center">Line</th> 
    15                     </tr> 
    16                     <xsl:for-each select="TestRun/FailedTests/FailedTest"> 
    17                         <tr> 
    18                             <td>
    19                                 <xsl:value-of select="Name"/>
    20                             </td>
    21                             <td align="center">
    22                                 <xsl:value-of select="FailureType"/>
    23                             </td> 
    24                             <td align="center"> 
    25                                 <xsl:value-of select="Message"/>
    26                             </td>
    27                             <xsl:for-each select="Location"> 
    28                                 <!-- <td>
    29                                     <xsl:value-of select="File"/>
    30                                 </td>  -->
    31                                 <td align="center">
    32                                     <xsl:value-of select="Line"/>
    33                                 </td> 
    34                             </xsl:for-each>
    35                             
    36                         </tr> 
    37                     </xsl:for-each> 
    38                 </table> 
    39 
    40                 <h2>测试通过用例:</h2> 
    41                 <table border="0" width="900px"> 
    42                     <tr bgcolor="#9acd32"> 
    43                         <th align="center">Name</th> 
    44                     </tr> 
    45                     <xsl:for-each select="TestRun/SuccessfulTests/Test"> 
    46                         <tr> 
    47                             <td align="left">
    48                                 <xsl:value-of select="Name"/>
    49                             </td>
    50                         </tr> 
    51                     </xsl:for-each> 
    52                 </table> 
    53 
    54                 <h2>结果统计:</h2> 
    55                 <table border="0" width="500px"> 
    56                     <tr bgcolor="#E0E0E0"> 
    57                         <th align="center">Tests</th> 
    58                         <th align="center">FailuresTotal</th> 
    59                         <th align="center">Errors</th> 
    60                         <th align="center">Failures</th> 
    61                     </tr> 
    62                     <xsl:for-each select="TestRun/Statistics"> 
    63                         <tr> 
    64                             <td align="center">
    65                                 <xsl:value-of select="Tests"/>
    66                             </td>
    67                             <td align="center"> 
    68                                 <xsl:value-of select="FailuresTotal"/>
    69                             </td> 
    70                             <td align="center">
    71                                 <xsl:value-of select="Errors"/>
    72                             </td> 
    73                             <td align="center">
    74                                 <xsl:value-of select="Failures"/>
    75                             </td>
    76                         </tr> 
    77                     </xsl:for-each> 
    78                 </table> 
    79             </body> 
    80         </html> 
    81     </xsl:template> 
    82 </xsl:stylesheet> 
    83 
    84 <!-- 
    85 1、代码第一行声明XSL文件的编码模式。  
    86 2、代码第二行是正确的声明XSL样式表,可以用xsl:stylesheet也可以用xsl:transform。  
    87 3、代码第三行,声明输出方式是Html,编码方式是utf-8。  
    88 4、<xsl:for-each>选取指定的节点集中的每个 XML 元素。  
    89 5、<xsl:value-of> 元素用于提取某个选定节点的值,并把值添加到转换的输出流中。 
    90 -->

    xxx.xml代码如下:

     1 <?xml version="1.0" encoding="utf-8" standalone='yes' ?> 
     2 <?xml-stylesheet type="text/xsl" href="parseXML2HTML.xsl"?>
     3 <TestRun>
     4   <FailedTests>
     5     <FailedTest id="2">
     6       <Name>SKF_ChangeDevAuthKeyTest::testcase01</Name>
     7       <FailureType>Assertion</FailureType>
     8       <Location>
     9         <File>f:dropboxvisual studio 2008projectssmartctcapi_cppunit	runksourcemsvc10smartctcapi_cppunit(vs2010)positivetest_cppskf_changedevauthkeytest.cpp</File>
    10         <Line>108</Line>
    11       </Location>
    12       <Message>assertion failed- Expression: rv2 == SAR_OK</Message>
    13     </FailedTest>
    14     <FailedTest id="3">
    15       <Name>SKF_ChangeDevAuthKeyTest::testcase02</Name>
    16       <FailureType>Assertion</FailureType>
    17       <Location>
    18         <File>f:dropboxvisual studio 2008projectssmartctcapi_cppunit	runksourcemsvc10smartctcapi_cppunit(vs2010)positivetest_cppskf_changedevauthkeytest.cpp</File>
    19         <Line>140</Line>
    20       </Location>
    21       <Message>assertion failed- Expression: rv2 == SAR_OK</Message>
    22     </FailedTest>
    23     <FailedTest id="4">
    24       <Name>SKF_ChangeDevAuthKeyTest::testcase03</Name>
    25       <FailureType>Assertion</FailureType>
    26       <Location>
    27         <File>f:dropboxvisual studio 2008projectssmartctcapi_cppunit	runksourcemsvc10smartctcapi_cppunit(vs2010)positivetest_cppskf_changedevauthkeytest.cpp</File>
    28         <Line>166</Line>
    29       </Location>
    30       <Message>assertion failed- Expression: rv2 == SAR_OK</Message>
    31     </FailedTest>
    32     <FailedTest id="5">
    33       <Name>SKF_ChangeDevAuthKeyTest::testcase04</Name>
    34       <FailureType>Assertion</FailureType>
    35       <Location>
    36         <File>f:dropboxvisual studio 2008projectssmartctcapi_cppunit	runksourcemsvc10smartctcapi_cppunit(vs2010)positivetest_cppskf_changedevauthkeytest.cpp</File>
    37         <Line>192</Line>
    38       </Location>
    39       <Message>assertion failed- Expression: rv2 == SAR_OK</Message>
    40     </FailedTest>
    41     <FailedTest id="7">
    42       <Name>SKF_DevAuthTest::testcase01</Name>
    43       <FailureType>Assertion</FailureType>
    44       <Location>
    45         <File>f:dropboxvisual studio 2008projectssmartctcapi_cppunit	runksourcemsvc10smartctcapi_cppunit(vs2010)positivetest_cppskf_devauthtest.cpp</File>
    46         <Line>110</Line>
    47       </Location>
    48       <Message>assertion failed- Expression: rv2 == SAR_OK</Message>
    49     </FailedTest>
    50     <FailedTest id="13">
    51       <Name>SKF_TransmitTest::testcase01</Name>
    52       <FailureType>Assertion</FailureType>
    53       <Location>
    54         <File>f:dropboxvisual studio 2008projectssmartctcapi_cppunit	runksourcemsvc10smartctcapi_cppunit(vs2010)positivetest_cppskf_transmittest.cpp</File>
    55         <Line>97</Line>
    56       </Location>
    57       <Message>assertion failed- Expression: rv2 == SAR_OK</Message>
    58     </FailedTest>
    59   </FailedTests>
    60   <SuccessfulTests>
    61     <Test id="1">
    62       <Name>SKF_CancelWaitForDevEventTest::testcase01</Name>
    63     </Test>
    64     <Test id="6">
    65       <Name>SKF_ConnectDevTest::testcase01</Name>
    66     </Test>
    67     <Test id="8">
    68       <Name>SKF_DisconnectDevTest::testcase01</Name>
    69     </Test>
    70     <Test id="9">
    71       <Name>SKF_EnumDevTest::testcase01</Name>
    72     </Test>
    73     <Test id="10">
    74       <Name>SKF_GetDevInfoTest::testcase01</Name>
    75     </Test>
    76     <Test id="11">
    77       <Name>SKF_GetDevStateTest::testcase01</Name>
    78     </Test>
    79     <Test id="12">
    80       <Name>SKF_LockDevTest::testcase01</Name>
    81     </Test>
    82     <Test id="14">
    83       <Name>SKF_UnlockDevTest::testcase01</Name>
    84     </Test>
    85   </SuccessfulTests>
    86   <Statistics>
    87     <Tests>14</Tests>
    88     <FailuresTotal>6</FailuresTotal>
    89     <Errors>0</Errors>
    90     <Failures>6</Failures>
    91   </Statistics>
    92 </TestRun>
  • 相关阅读:
    Pandas | 21 日期功能
    Pandas | 20 级联
    Pandas | 19 合并/连接
    Pandas | GroupBy 分组
    Pandas | 缺失数据处理
    Pandas | 16 聚合
    Pandas | 15 窗口函数
    Pandas | 14 统计函数
    Pandas | 13 索引和选择数据
    Pandas | 12 选项和自定义
  • 原文地址:https://www.cnblogs.com/zhangxiaosong/p/3372442.html
Copyright © 2020-2023  润新知