繁体   English   中英

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

[英]Is there a Linux command line tool sequence for converting XML files into a single HTML file?

我有一堆XML文件,我想将它们可视化为HTML文件中的表格。 我在网上搜索了有关XML-> HTML转换的教程,并找到一堆描述HTML / XML / JSON转换命令行工具的博客。

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

编辑:更多背景信息。

我实际上想分析我用来开发几何算法的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确实会在命令行上生成漂亮的彩色输出,但是对于数十个applicatins(每个包含约10个测试),我需要向上滚动以查看失败的原因。

XML是一种格式家族,因为它是一种标记语言 (例如XHTMLDocbook等),而不是一种特定的格式。 您需要精确地知道XML文件遵循哪种XML模式

您可能需要一些XSLT处理器(或Xquery )。 另请参见SAX解析器Expat

除了使用XSLT进行转换外,您可能还想看看David Lee的xmlsh,它是一种用于定义XML处理管道的类外壳工具(还有XProc和Ant广泛用于此目的,但是我建议您使用xmlsh似乎是壳扇)。

此输入的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处理器。 如果选择撒克逊语,命令将是

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM