Hi everyone,
I have the following XML (simplification):
<?xml version="1.0" encoding="utf-8"?>
<TestCases>
<TestCase>
<Name>Test1</Name>
<Result>Failed</Result>
<Properties>
<Type>Type1</Type>
</Properties>
</TestCase>
<TestCase>
<Name>Test1</Name>
<Result>Failed</Result>
<Properties>
<Type>Type2</Type>
</Properties>
</TestCase>
<TestCase>
<Name>Test1</Name>
<Result>Passed</Result>
<Properties>
<Type>Type1</Type>
</Properties>
</TestCase>
</TestCases>
I am interested to create a table that counts the number of passed/failed test cases, according to their type, like so:
Passed (Type1): 1 Failed (Type1): 1 Passed (Other types): 0 Failed (Other types): 1
To do that I am writing the following query:
<xsl:value-of select="count(//TestCase[Result = 'Passed' and count(Properties/TestType='Type1')>0])"/>
<xsl:value-of select="count(//TestCase[Result = 'Failed' and count(Properties/TestType='Type1')>0])"/>
<xsl:value-of select="count(//TestCase[Result = 'Passed' and count(Properties/TestType='Type1')=0])"/>
<xsl:value-of select="count(//TestCase[Result = 'Failed' and count(Properties/TestType='Type1')=0])"/>
As you can see, there is a LOT of code repetition going and would be great if I could save some of it. I understand that in XSL 2.0 I could use user functions for it, but what should I do in XSL 1.0? Do you see any options you can see to optimize the repeating expressions?
P.S Note that is a simplifications of the real and while the expression doesn't seem long here, in the real code it is quite longer so the need is quite real.
Thanks!