[xsl] XSLT2 grouping over multiple documents

Subject: [xsl] XSLT2 grouping over multiple documents
From: "Thomas J. Sebestyen" <a9105535@xxxxxxxxxxxxxxxxx>
Date: Thu, 23 Jun 2005 01:49:57 +0200
Hello,

I have a couple of xml-documents, all with the same structure:

<?xml version="1.0" encoding="UTF-8"?>
<responses>
	<response for="js0" correct="correct">C</response>
	<response for="js1">A</response>
	<response for="js2" correct="correct">A</answer>
	<response for="db0" correct="correct">A</response>
	<response for="db1">B</response>
 ...
</responses>


I use an xml-file to collect all this documents:

<?xml version="1.0" encoding="UTF-8"?>
<alldocs>
	<a href="184855.xml" />
	<a href="190026.xml" />
 ...
</alldocs>

I woul like to group all <response> by  @for over all documents and then
count how many from them has an @correct.
My solution is the following (which works for me):

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="html" indent="yes" encoding="iso-8859-1" />
  <xsl:template match="/alldocs">
    <xsl:variable name="alldocs">
      <xsl:for-each select="document(a/@href)">
        <xsl:copy-of select="/responses/response" />
      </xsl:for-each>
    </xsl:variable>
    <html>
      <head><title>Responses</title></head>    
      <body>
        <xsl:for-each-group select="$alldocs/response" group-by="@for">
          <p>
            <b><xsl:value-of select="current-grouping-key()" />=</b>
            <xsl:for-each-group select="current-group()"
group-by="@correct">
              <xsl:value-of select="count(current-group())" />
            </xsl:for-each-group>
          </p>
        </xsl:for-each-group>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

Is there a better solution?
(for exmaple if I would like to sort the output by the number of
@corrects)

Regards
Thomas

Current Thread