xslt - xsltproc add text before and after multiple files -
i'm using xsltproc utility transform multiple xml test results pretty printed console output using command following.
xsltproc stylesheet.xslt testresults/* where stylesheet.xslt looks this:
<!-- 1 testsuite per xml test report file --> <xsl:template match="/testsuite"> <xsl:text>begin</xsl:text> ... <xsl:text>end</xsl:text> </xsl:template> this gives me output similar this:
begin testsuite: 1 end begin testsuite: 2 end begin testsuite: 3 end what want following:
begin testsuite: 1 testsuite: 2 testsuite: 3 end googling turning empty. suspect might able merge xml files somehow before give them xsltproc, hoping simpler solution.
xsltproc transforms each specified xml document separately, indeed sensible thing because xslt operates on single source tree, , xsltproc doesn't have enough information compose multiple documents single tree. since template emits text nodes "begin" , "end" text, nodes emitted each input document.
there several ways arrange have 1 "begin" , 1 "end". all of reasonable ones start lifting text nodes out template <testsuite> elements. if each "testsuite:" line in output should correspond 1 <testsuite> element you'll need if physically merge input documents.
one solution remove responsibility "begin" , "end" lines xslt altogether. example, remove xsl:text elements stylesheet , write simple script such this:
echo begin xsltproc stylesheet.xslt testresults/* echo end alternatively, if individual xml files not start xml declarations, might merge them dynamically, running xsltproc command such this:
{ echo "<suites>"; cat testresults/*; echo "</suites>"; } \ | xsltproc stylesheet.xslt - the corresponding stylesheet might take form along these lines:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text"/> <xsl:template match="/suites"> <!-- transform of root element produces "begin" , "end" --> <xsl:text>begin
</xsl:text> <xsl:apply-templates select="testsuite"/> <xsl:text>
end</xsl:text> </xsl:template> <xsl:template match="testsuite"> ... </xsl:template> </xsl:stylesheet>
Comments
Post a Comment