Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSL how to count number of nodes depending on value without using attributes?

Tags:

xml

xslt

I have done research, but I found only solutions when operating on attributes.

I have recently started to study XSL. I would like to use it to transform my xml file into html one. The data that I want to extract should present how many nodes have certain value.

XML has following structure:

<Tests>
    <Test>
        <TestName> a </TestName>
        <Date> 12.11.10 </Date>
        <Result> Fail </Result>
    </Test>
    <Test>
        <TestName> b </TestName>
        <Date> 13.11.10 </Date>
        <Result> Fail </Result>
    </Test>
    <Test>
        <TestName> c </TestName>
        <Date> 14.11.10 </Date>
        <Result> Pass </Result>
    </Test>
</Tests>

what I want as an out is: 2 (number of Fails) 1 (number of Passes)

any could give me a hand with this task ?

like image 928
Artur Avatar asked Dec 06 '10 09:12

Artur


1 Answers

Maybe:

<xsl:value-of select="count(Tests/Test[normalize-space(Result)='Fail'])" />
like image 125
Björn Avatar answered Oct 10 '22 04:10

Björn