私はこのようなXMLを持っています:
<assessment>
<variables>
<variable>
<attributes>
<variable_name value="FRED"/>
</attributes>
</variable>
</variables>
<variables>
<variable>
<attributes>
<variable_name value="MORTIMER"/>
</attributes>
</variable>
</variables>
<variables>
<variable>
<attributes>
<variable_name value="FRED"/>
</attributes>
</variable>
</variables>
</assessment>
私はこのXSLTでそれを知っています:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="html"/>
<xsl:template match="assessment">
<xsl:for-each select=".//variables/variable/attributes/variable_name">
<xsl:value-of select="@value"/>
<br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
次のように出力できます。
FRED
MORTIMER
FRED
しかし、私が本当に出力したいのはこれです:
FRED: 2
MORTIMER: 1
つまり、個別の要素と、それぞれが発生する回数をリストしたいと思います。要素を最初に表示された順序で表示したいことに注意してください(これにより、並べ替えを使用する一部のソリューションが除外される可能性があります)。
どうすればよいですか?