I’m trying to parse an xml file output from googletest to display the results in a pretty way in an html page. I have had a fair crack at it and have a working solution. Only one thing left to do.
Currently each class has a header and each function+test is displayed underneath, I’m looking for a way to extract the function name from the xml attribute to have it as its own sub-heading. Example below
Current Output
Class Name
functionName_testName
functionName_test2Name
function2Name_testName
Desired Output
Class Name
functionName
testName
test2Name
function2Name
testName
XML To be Parsed
<testsuite name="testPacketProcessor" tests="27" failures="0" disabled="0" errors="0" time="36.875">
<testcase name="testInitialise_IpNotSet" status="run" time="0" classname="testPacketProcessor" />
<testcase name="testInitialise_GoodIp" status="run" time="2.046" classname="testPacketProcessor" />
<testcase name="testInitialise_BadIp" status="run" time="0.032" classname="testPacketProcessor" />
</testsuite>
XSL Currently Implemented
<xsl:for-each select="testsuites/testsuite">
<div class="testHeading">
<span><xsl:value-of select="substring-after(@name,'test')"/></span>
</div>
<xsl:for-each select="testcase">
<div class="testReport">
<xsl:if test="not(starts-with(@name,'DISABLED'))"><xsl:value-of select="substring-after(@name,'test')"/></xsl:if>
<xsl:if test="starts-with(@name,'DISABLED')"><xsl:value-of select="substring-after(@name,'DISABLED_test')"/></xsl:if>
<xsl:text> - </xsl:text>
<xsl:if test="starts-with(@status,'run')">
<xsl:if test="failure"><xsl:text>Fail</xsl:text></xsl:if>
<xsl:if test= "not(failure)"><xsl:text>Pass</xsl:text></xsl:if>
</xsl:if>
<xsl:if test="starts-with(@status,'not')"><xsl:text>Disabled</xsl:text></xsl:if>
</div>
</xsl:for-each>
</xsl:for-each>
Using the above xml as an example I would like a subheading of “Initialise” under the packet processor heading with each test doucumented under the subheading
Any advice on the best way to go about this would be much appreciated. I’ve looked at xsl variables but cannot fathom how to deal with not being able to change the value. Have also read a little on xsl templates and recursion but I’m not sure how that would work for this situation.
Thanks in advance
Dougie
This transformation produces the subheading and name for each testcase:
When applied on the provided XML document:
the wanted, correct result is produced:
Explanation: Using the standard XPath functions
substring-before()andsubstring-after()Edit: In a comment the OP clarified that he wanted grouping by function (tired of bad questions ?):
This transformation performs the wanted grouping:
and produces the wanted result: