I want to calculate the sum of attributes using xslt 1.0. below is the xml file as an input.
<?xml version="1.0" encoding="UTF-8"?>
<alltestsuites>
<testsuite tests="2" failures="0" disabled="1" errors="0" pass="1">
<testcase name="test1" file="abc.cpp" status="pass" />
<testcase name="test2" file="def.cpp" status="disabled" />
</testsuite>
<testsuite tests="2" failures="1" disabled="1" errors="0" pass="0">
<testcase name="test1" file="ghi.cpp" status="disabled" />
<testcase name="test2" file="jkl.cpp" status="failure" />
</testsuite>
<testsuite tests="2" failures="0" disabled="2" errors="0" time="0">
<testcase name="test1" file="jkl.cpp" status="disabled" />
<testcase name="test2" file="mno.cpp" status="disabled" />
</testsuite>
</alltestsuites>
Basically I am trying to calculate the sum of tests, failure, disabled and error from each testsuite. Thank you for the help.
CodePudding user response:
Try
<xsl:value-of select="sum(/alltestsuites/testsuite/@tests)"/>
AFAICT, the same result could be obtained by:
<xsl:value-of select="count(/alltestsuites/testsuite/testcase)" />