Counting distinct items in XSLT independent of depth
问题 If I run the following XSLT code: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:key name="kValueByVal" match="variable_name/@value" use="."/> <xsl:template match="assessment"> <xsl:for-each select=" /*/*/variable/attributes/variable_name/@value [generate-id() = generate-id(key('kValueByVal', .)[1]) ] "> <xsl:value-of select= "concat(., ' ', count(key('kValueByVal', .)), '
')"/> </xsl:for-each> </xsl:template> </xsl:stylesheet>