Hello, I'm trying to sort my xml by the number of occurrences of the "response" element with the attribute "id" and get just a summary.
<person id="1">
<answer id="A"/>
<answer id="B"/>
</person>
<person id="2">
<answer id="A"/>
<answer id="C"/>
</person>
<person id="3">
<answer id="C"/>
</person>
I want just the summary text in the output:
A = 2 times (s)
C = 2 times (s)
B = 1 times (s)
In XSLT 2.0, I tried:
<xsl:for-each select="distinct-values(/person/answer)">
<xsl:sort select="count(/person/answer)" data-type="number"/>
<xsl:value-of select="./@id"/> =
<xsl:value-of select="count(/person/answer[@id=./@id])"/> time(s)
</xsl:for-each>
but it does not work:
in XMLSpy 2008:
"Error in XPath 2.0 expression Not node element"
in Saxon 9:
XPTY0020: Leading '/' cannot select the root of the tree node containing the context element: the context element is an atomic value
. The style sheet could not be compiled. 1 error detected.
Tommy