My goal is to count how many of 'interfaces' from interface_list.xml are connected to 'testcases'. I have a list of interfaces in separate .xml. If intercace is connected to number of testcases greater than 0 it should be counted. My idea was to use double count function, first count is counting occurrences of one interface inside 'extednedinfo' of 'testcase' and main count should count how many of them are greater than 0 but unfortunately it is not working. Im using xslt 1.0 and sablotron.
<xsl:template match="/testmodule" mode="testedinterfaces">
<xsl:variable name="testmodule" select="." />
<xsl:for-each select="$interface_list/interfaces/interface">
<xsl:variable name="nInterfacesTested"><xsl:value-of select="count(count($testmodule/testgroup/testcase[contains(extendedinfo, current()/ID)])> 0)"/></xsl:variable>
</xsl:for-each>
<tr>
<td >Overall number of tested interfaces </td>
<td width="60"><xsl:value-of select="$nInterfacesTested"/></td>
<td />
</tr>
</xsl:template>
here I want o count occurrences:
<testmodule starttime="2022-07-27 16:29:54" timestamp="1397.491492" verdicts="2_basic" measurementid="ad20a6c0">
<testgroup>
<testcase starttime="2022-07-27 16:29:54" timestamp="1397.491492">
<extendedinfo type="text">[12345][654321][123654]</extendedinfo>
</testcase>
<testcase starttime="2022-07-27 16:30:18" timestamp="1421.291492">
<extendedinfo type="text">[12345]</extendedinfo>
</testcase>
<testcase starttime="2022-07-27 16:30:42" timestamp="1445.091492">
<extendedinfo type="text">[654321]</extendedinfo>
</testcase>
<testcase starttime="2022-07-27 16:31:06" timestamp="1468.891492">
<extendedinfo type="text">[123654]</extendedinfo>
</testcase>
</testgroup>
</testmodule>
file: interface_list.xml
<header_xml>
<interface>12345</interface>
<interface>654321</interface>
<interface>123654</interface>
<interface>112233</interface>
<interface>999999</interface>
<interface>888888</interface>
</header_xml>
the result should be 4.
CodePudding user response:
This would not be my preferred solution but to do this in pure XSLT 1.0 without any extensions, you could do:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:param name="interface_list" select="document('interface_list.xml')" />
<xsl:template match="/testmodule">
<xsl:variable name="testmodule" select="." />
<xsl:variable name="matches">
<xsl:for-each select="$interface_list/header_xml/interface">
<xsl:if test="$testmodule/testgroup/testcase[contains(extendedinfo, concat('[', current(), ']'))]">x</xsl:if>
</xsl:for-each>
</xsl:variable>
<result>
<xsl:value-of select="string-length($matches)"/>
</result>
</xsl:template>
</xsl:stylesheet>
The result in the given example is 3
, not 4
.