Number of nodes meeting a conditional based on attributes
-
01-07-2019 - |
Question
Below is part of the XML which I am processing with PHP's 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, that would be 2.
I've tried looping and incrementing a counter variable, but I can't redefine variables.
I've tried lots of combinations of xsl:number, with count/from, but couldn't get the XPath expression right.
Thanks!
Solution
<xsl:value-of select="count(/result/uf[@y=@x])" />
OTHER TIPS
count('/result/uf[@x = @y]')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow