xsltproc在多个文件之前和之后添加文本

xsltproc在多个文件之前和之后添加文本,xslt,xslt-1.0,libxslt,Xslt,Xslt 1.0,Libxslt,我使用xsltproc实用程序,使用如下命令将多个xml测试结果转换为打印精美的控制台输出 xsltproc stylesheet.xslt testresults/* 其中stylesheet.xslt如下所示: <!-- One testsuite per xml test report file --> <xsl:template match="/testsuite"> <xsl:text>begin</xsl:text> ...

我使用
xsltproc
实用程序,使用如下命令将多个xml测试结果转换为打印精美的控制台输出

xsltproc stylesheet.xslt testresults/*
其中
stylesheet.xslt
如下所示:

<!-- One testsuite per xml test report file -->
<xsl:template match="/testsuite">
  <xsl:text>begin</xsl:text>
  ...
  <xsl:text>end</xsl:text>
</xsl:template>
我想要的是:

begin
TestSuite: 1
TestSuite: 2
TestSuite: 3
end

谷歌搜索结果是空的。我怀疑在我将xml文件交给
xsltproc
之前,我可能能够以某种方式合并xml文件,但我希望有一个更简单的解决方案。

xsltproc
单独转换每个指定的xml文档,这确实是它唯一明智的做法,因为XSLT在一个源代码树上运行,而且
xsltproc
没有足够的信息将多个文档组成一个树。由于模板会发出带有“开始”和“结束”文本的文本节点,所以会为每个输入文档发出这些节点

有几种方法可以安排只有一个“开始”和一个“结束”。所有合理的方法都是从提升
元素的模板文本节点开始。如果输出中的每个“TestSuite:”行都应该对应一个
元素,那么即使您实际合并了输入文档,也需要这样做

一种解决方案是从XSLT中删除“开始”和“结束”行的责任。例如,从样式表中删除
xsl:text
元素,并编写如下简单脚本:

echo begin
xsltproc stylesheet.xslt testresults/*
echo end
{ echo "<suites>"; cat testresults/*; echo "</suites>"; } \
    | xsltproc stylesheet.xslt -
或者,如果单个XML文件不以XML声明开头,则可以通过使用以下命令运行
xsltproc
动态合并它们:

echo begin
xsltproc stylesheet.xslt testresults/*
echo end
{ echo "<suites>"; cat testresults/*; echo "</suites>"; } \
    | xsltproc stylesheet.xslt -
{echo”“;cat testresults/*;echo”“;}\
|xsltproc stylesheet.xslt-
相应的样式表可能会采用以下形式:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>

  <xsl:template match="/suites">
    <!-- the transform of the root element produces the "begin" and "end" -->
    <xsl:text>begin&#x0A;</xsl:text>
    <xsl:apply-templates select="testsuite"/>
    <xsl:text>&#x0A;end</xsl:text>
  </xsl:template>

  <xsl:template match="testsuite">
    ...
  </xsl:template>
</xsl:stylesheet>

开始
;

;结束
...

xsltproc
分别转换每个指定的XML文档,因为XSLT在单个源代码树上运行,并且
xsltproc
没有足够的信息将多个文档组合到一个树中,所以这确实是它唯一明智的做法。由于模板会发出带有“开始”和“结束”文本的文本节点,所以会为每个输入文档发出这些节点

有几种方法可以安排只有一个“开始”和一个“结束”。所有合理的方法都是从提升
元素的模板文本节点开始。如果输出中的每个“TestSuite:”行都应该对应一个
元素,那么即使您实际合并了输入文档,也需要这样做

一种解决方案是从XSLT中删除“开始”和“结束”行的责任。例如,从样式表中删除
xsl:text
元素,并编写如下简单脚本:

echo begin
xsltproc stylesheet.xslt testresults/*
echo end
{ echo "<suites>"; cat testresults/*; echo "</suites>"; } \
    | xsltproc stylesheet.xslt -
或者,如果单个XML文件不以XML声明开头,则可以通过使用以下命令运行
xsltproc
动态合并它们:

echo begin
xsltproc stylesheet.xslt testresults/*
echo end
{ echo "<suites>"; cat testresults/*; echo "</suites>"; } \
    | xsltproc stylesheet.xslt -
{echo”“;cat testresults/*;echo”“;}\
|xsltproc stylesheet.xslt-
相应的样式表可能会采用以下形式:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>

  <xsl:template match="/suites">
    <!-- the transform of the root element produces the "begin" and "end" -->
    <xsl:text>begin&#x0A;</xsl:text>
    <xsl:apply-templates select="testsuite"/>
    <xsl:text>&#x0A;end</xsl:text>
  </xsl:template>

  <xsl:template match="testsuite">
    ...
  </xsl:template>
</xsl:stylesheet>

开始
;

;结束
...