使用:
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.
它是一個應用程序,顯示@root以及如何他們經常發生每所有發現的價值,這就是爲什麼我需要查詢值。 – Jelmervdl
我更新了我的答案;我最初誤解了你的問題。 – gioele
但是,如何明確地要求「如何計算每個值的出現」? – Gunther