[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSLT2 grouping over multiple documents

Subject: XSLT2 grouping over multiple documents
From: "Thomas J. Sebestyen" <a9105535@xxxxxxxxxxxxxxxxx>
Date: Thu, 23 Jun 2005 01:49:57 +0200
multiple grouping xsl
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.