Number of nodes satisfying the attribute-based condition

The following is the XML part that I am processing using PHP XSLTProcessor :

<result>
    <uf x="20" y="0"/>
    <uf x="22" y="22"/>
    <uf x="4" y="3"/>
    <uf x="15" y="15"/>
</result>

I need to know how many "uf" nodes exist, where x == y.

In the above example, this will be 2.

I tried a loop and incremented the counter variable, but I cannot redefine the variables.

I tried many combinations of xsl: number, with count / from, but could not get the correct XPath expression.

Thank!

+3
source share
2 answers
<xsl:value-of select="count(/result/uf[@y=@x])" />
+5
source
count('/result/uf[@x = @y]')
+1
source

Source: https://habr.com/ru/post/1697213/


All Articles