You can collect all Result elements from three documents using something like
<xsl:variable name="allResults" select="(/ | document('file2.xml') | document('file3.xml'))//Result" />
and then apply predicates to this to count the elements you are interested in, for example
<xsl:value-of select=" count($allResults[@testName = 'TestOne'][@outcome = 'Failed'])" />
Instead of a fixed set of file names, if you have a basic index.xml that lists all the files you want to merge, for example:
<list> <entry name="File1.xml" /> <entry name="File2.xml" /> <entry name="File3.xml" /> </list>
then you can use this index as the main input to the stylesheet, and the allResults variable will look like this:
<xsl:variable name="allResults" select="document(/list/entry/@name)//Result" />
When you pass the node installed in the document function, it takes a string value of each node in turn and treats it as the URI of the loaded file, returning the result set of the document root nodes.
Here is a complete example.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:variable name="allResults" select="document(/list/entry/@name)//Result" /> <xsl:template match="/"> <xsl:variable name="name" select="'TestOne'" /> <h2>Totals</h2> <table border="1" cellSpacing="0" cellPadding="5" > <tr bgcolor="#9acd32"> <th>Test Name</th> <th>Total Passed</th> <th>Total Failed</th> </tr> <tr> <td><xsl:value-of select="$name"/></td> <td><xsl:value-of select="count($allResults[@testName = $name] [@outcome = 'Passed'])"/></td> <td><xsl:value-of select="count($allResults[@testName = $name] [@outcome = 'Failed'])"/></td> </tr> </table> </xsl:template> </xsl:stylesheet>
source share