如何计算 XSLT 版本 1 中属性的整数值之和

How to calculate the sum of integer values of an attributes in XSLT version 1

我想使用 xslt 1.0 计算属性总和。下面是 xml 文件作为输入。

<?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>

基本上我正在尝试计算每个测试套件的测试、失败、禁用和错误的总和。 谢谢你的帮助。

尝试

<xsl:value-of select="sum(/alltestsuites/testsuite/@tests)"/>

AFAICT,可以通过以下方式获得相同的结果:

<xsl:value-of select="count(/alltestsuites/testsuite/testcase)" />