是否有用于将XML文件转换为单个HTML文件的Linux命令行工具序列?

时间:2014-07-18 08:36:48

标签: html xml linux command-line

我有一堆XML文件,我想将它们可视化为HTML文件中的表格。我在网上搜索了a tutorial on XML->HTML conversion,以及一些描述HTML / XML / JSON转换命令行工具的博客。

是否可以使用Linux中的命令行工具将一堆XML文件转换为HTML文件,其中每个XML文件都表示为table

编辑:更多背景信息。

我实际上想分析Google Test的XML输出,我用它来开发几何算法。以下是单个测试应用程序的XML外观:

<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="27" failures="0" disabled="0" errors="0" timestamp="2014-07-18T10:27:10" time="0.002" name="AllTests">
  <testsuite name="lineSegmentIntersection" tests="3" failures="0" disabled="0" errors="0" time="0">
    <testcase name="halfspaceNoIntersection" status="run" time="0" classname="lineSegmentIntersection" />
    <testcase name="halfspacePointIntersection" status="run" time="0" classname="lineSegmentIntersection" />
    <testcase name="halfspaceRegularIntersection" status="run" time="0" classname="lineSegmentIntersection" />
  </testsuite>
  <testsuite name="polygonIntersection" tests="6" failures="0" disabled="0" errors="0" time="0">
    <testcase name="halfspaceNoIntersection" status="run" time="0" classname="polygonIntersection" />
    <testcase name="halfspacePointFullIntersection" status="run" time="0" classname="polygonIntersection" />
    <testcase name="halfspacePointIntersection" status="run" time="0" classname="polygonIntersection" />
    <testcase name="halfspaceEdgeIntersection" status="run" time="0" classname="polygonIntersection" />
    <testcase name="halfspaceDiagonalIntersection" status="run" time="0" classname="polygonIntersection" />
    <testcase name="halfspaceRegularIntersection" status="run" time="0" classname="polygonIntersection" />
  </testsuite>
  <testsuite name="aabboxIntersection" tests="5" failures="0" disabled="0" errors="0" time="0">
    <testcase name="AABBtrueIntersection" status="run" time="0" classname="aabboxIntersection" />
    <testcase name="AABBpointIntersection" status="run" time="0" classname="aabboxIntersection" />
    <testcase name="AABBedgeIntersection" status="run" time="0" classname="aabboxIntersection" />
    <testcase name="AABBfaceIntersection" status="run" time="0" classname="aabboxIntersection" />
    <testcase name="AABBnoIntersection" status="run" time="0" classname="aabboxIntersection" />
  </testsuite>
  <testsuite name="polyhedronIntersection" tests="11" failures="0" disabled="0" errors="0" time="0.002">
    <testcase name="AABBpointIntersection" status="run" time="0.001" classname="polyhedronIntersection" />
    <testcase name="AABBedgeIntersection" status="run" time="0" classname="polyhedronIntersection" />
    <testcase name="AABBfaceIntersection" status="run" time="0" classname="polyhedronIntersection" />
    <testcase name="AABBtrueIntersection" status="run" time="0" classname="polyhedronIntersection" />
    <testcase name="halfspacePointIntersection" status="run" time="0" classname="polyhedronIntersection" />
    <testcase name="halfspaceEdgeIntersection" status="run" time="0" classname="polyhedronIntersection" />
    <testcase name="halfspaceFaceEmptyIntersection" status="run" time="0" classname="polyhedronIntersection" />
    <testcase name="halfspaceFaceFullIntersection" status="run" time="0" classname="polyhedronIntersection" />
    <testcase name="cubeSpatialDiagonalIntersection" status="run" time="0" classname="polyhedronIntersection" />
    <testcase name="cubeHalvedIntersection" status="run" time="0" classname="polyhedronIntersection" />
    <testcase name="cubeHalvedDiagonally" status="run" time="0.001" classname="polyhedronIntersection" />
  </testsuite>
  <testsuite name="inside" tests="2" failures="0" disabled="0" errors="0" time="0">
    <testcase name="halfspaceTriangle" status="run" time="0" classname="inside" />
    <testcase name="halfspaceTetrahedron" status="run" time="0" classname="inside" />
  </testsuite>
</testsuites>

我为不同的几何操作实现了许多测试应用程序,它们都生成了这样的XML文件。随着测试数量的增加,我正在失去概述,因为我正在编译(通用C ++代码)并且每次实现处理几何的源代码中的更改时都执行所有这些。这就是为什么我想选择所有这些并以表格形式以某种方式将它们可视化的原因。

Google Test确实为命令行生成了一个很好的彩色输出,但是对于几十个应用程序,每个包含~10个测试,我需要向上滚动以查看失败的内容。

2 个答案:

答案 0 :(得分:1)

XML更像是一系列格式 - 因为它是markup language - (例如XHTMLDocbook,...)而非特定格式。您需要知道正好您的XML文件遵循哪个XML schema

你可能想要一些XSLT处理器(或者Xquery)。另请参阅SAX parsersExpat

答案 1 :(得分:1)

除了要进行转换的XSLT之外,您还可以查看David Lee的xmlsh,它是一个类似于shell的工具,用于定义XML处理管道(还有广泛的XProc和Ant)用于此目的,但我建议xmlsh,因为你似乎是一个shell粉丝。)

此输入的XSLT转换可能如下所示:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
   <head>...</head>
   <body><xsl:apply-templates/></body>
  </html>
</xsl:template>

<xsl:template match="testsuites">
  <table>
    <thead>
      <tr><th>name</th><th>.....</th>
    </thead>
    <tbody>
      <xsl:apply-templates/>
    </tbody>
  </table>
</xsl:template>

<xsl:template match="testcase">
  <tr>
   <td><xsl:value-of select="@name"/>
   <td><xsl:value-of select="@status"/>
   <td><xsl:value-of select="@time"/>
   <td><xsl:value-of select="@classname"/>
  </tr>
</xsl:template>

</xsl:stylesheet>

您可以从命令行使用许多XSLT处理器。如果选择Saxon,命令将是

java -jar saxon9.jar -s:source.xml -xsl:stylesheet.xsl -o:output.html