Используйте
concat('Having @root: ', count(//node[@rel='su']/@root ),
', Not having @root: ', count(//node[@rel='su'][not(@root)]),
', Having @root occur ',
floor(count(//node[@rel='su']/@root ) div count(//node[@rel='su']) * 100),
'% of the time.'
)
Проверка на основе XSLT :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:value-of select=
"concat('Having @root: ', count(//node[@rel='su']/@root ),
', Not having @root: ', count(//node[@rel='su'][not(@root)]),
', Having @root occur ',
floor(count(//node[@rel='su']/@root ) div count(//node[@rel='su']) * 100),
'% of the time.'
)
"/>
</xsl:template>
</xsl:stylesheet>
Когда это преобразование применяется к следующему документу XML :
<t>
<node rel="su" root="2"/>
<node rel="su" root="1"/>
<node rel="su" />
<node rel="su" root="4"/>
<node rel="su" root="5"/>
<node rel="su" />
<node rel="su" root="7"/>
<node rel="su" root="8"/>
<node rel="su" />
<node rel="su" />
</t>
желаемый, правильный результат получается :
Having @root: 6, Not having @root: 4, Having @root occur 60% of the time.