I’m new to whole world writing code in xslt. I want the xsl code to look though every node/attributes in my xml file and search for ‘__(string)’ and count ‘result=success/failed’. I found a thread here on this site to help me out a little:
How do you do wildcard matches with XSLT?
I got my xsl code to find the string match. But then my problem is, I don’t know how to write the code to count success and failed for the given stringmatch? I wish for the output to look something like this:
**(Casename)** | **(total success)** | **(total failed)**
__(stringmatch1)| 2 | 0
__(stringmatch2)| 0 | 2
Here is a sample of the xml file:
<report>
<programtest user="testuser">
<programtest software="test">
<programtest testname="SW log">
</programtest>
<programtest testname="HW log">
</programtest>
<programtest testname="loop_program_test">
<programtest casename="test" iteration="1" result="success">
<programtest casename="__temp1" type="specifictestcase" result="success" >
</programtest>
<programtest casename="__temp2" type="specifictestcase" result="failed" >
</programtest>
</programtest>
<programtest casename="test" iteration="2" result="success">
<programtest casename="__temp1" type="specifictestcase" result="success" >
</programtest>
<programtest casename="__temp2" type="specifictestcase" result="failed" >
</programtest>
</programtest>
</programtest>
</programtest>
</programtest>
</report>
Any help is appreciated! 🙂
I think this is a grouping issue. You need to group your results by the @casename attribute for each specific programtest element. In XSLT2.0, you would do this by means of the xsl:for-each-group element
Then, for each group, you would get the number of successes like so
(N.B. There may be a typo in your XML, as shouldn’t it be ‘success’ and not ‘succes’?)
Here is the full XSLT
When applied to your sample XML, the following is output