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

Help with multiple key grouping...

Subject: Help with multiple key grouping...
From: "Hix, Robert W CIV NSWCDD, Q45" <robert.w.hix@xxxxxxxx>
Date: Mon, 19 Nov 2007 15:11:33 -0600
 Help with multiple key grouping...
Hello all,

I am really new to XSL and have run into a problem I can't get a handle
on.  I am developing a document tracking system that will help out with
letting employees know what documents are out for review, and when those
reviews are due.  I am also throwing in a list of all documents in the
library.  My current XML file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="gatorDocLibXsl_t3.xsl"?> <DocLib>
   <document>
      <title>Document 1</title>
      <version>3.0</version>
      <category>IRS</category>
      <docReview>
         <complete>0</complete>
         <dueDate>11/30/2007</dueDate>

<commentTemplateFile>c:\temp\reviewTemplate.xls</commentTemplateFile>
      </docReview>
      <adjudication>
         <date>12/1/2007</date>
      </adjudication>
   </document>
   <document>
      <title>Document 2</title>
      <version>0.1</version>
      <category>IRS</category>
      <docReview>
         <complete>0</complete>
         <dueDate>11/23/2007</dueDate>

<commentTemplateFile>c:\temp\reviewTemplate.xls</commentTemplateFile>
      </docReview>
      <adjudication>
         <date>12/5/2007</date>
      </adjudication>
   </document>
   <document>
      <title>Document 3</title>
      <version>0.2</version>
      <category>SRS</category>
      <docReview>
         <complete>1</complete>
         <dueDate>11/01/2007</dueDate>

<commentTemplateFile>c:\temp\reviewTemplate.xls</commentTemplateFile>
      </docReview>
      <adjudication>
         <date>1/5/2007</date>
      </adjudication>
   </document>
   <document>
      <title>Document 4</title>
      <version>1.0</version>
      <category>SSS</category>
      <docReview>
         <complete>0</complete>
         <dueDate>12/08/2007</dueDate>

<commentTemplateFile>c:\temp\reviewTemplate.xls</commentTemplateFile>
      </docReview>
      <adjudication>
         <date>12/10/2007</date>
      </adjudication>
   </document>
   <document>
      <title>Document 1</title>
      <version>2.0</version>
      <category>IRS</category>
      <docReview>
         <complete>1</complete>
         <dueDate>11/23/2007</dueDate>

<commentTemplateFile>c:\temp\reviewTemplate.xls</commentTemplateFile>
      </docReview>
      <adjudication>
         <date>12/1/2007</date>
      </adjudication>
   </document>
   <document>
      <title>Document 1</title>
      <version>1.0</version>
      <category>IRS</category>
      <docReview>
         <complete>1</complete>
         <dueDate>11/23/2007</dueDate>

<commentTemplateFile>c:\temp\reviewTemplate.xls</commentTemplateFile>
      </docReview>
      <adjudication>
         <date>12/1/2007</date>
      </adjudication>
   </document>
</DocLib>

So far I have figured out how to group my output by category.  I also
need to group the documents within the category by title so that I can
sort them by version number.  Below is my current stylesheet for
grouping by category.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <!-- Define keys for processing -->
   <xsl:key name="documentsByCategory" match="document" use="category"/>

   <!-- Main processing -->
   <xsl:template match="DocLib">
      <!-- Display all documents that are under review in a table-->
      <table border="1">
         <caption>Documents for Review</caption>
         <tr>
            <th>Document Title</th>
            <th>Version</th>
            <th>Due Date</th>
            <th>Adjudication Date</th>
            <th>Comment Template</th>
         </tr>

         <xsl:for-each select="document">

            <xsl:sort select="substring(docReview/dueDate,7,4)"/> <!--
Sort Day -->
            <xsl:sort select="substring(docReview/dueDate,1,2)"/> <!--
Sort Day -->
            <xsl:sort select="substring(docReview/dueDate,4,2)"/> <!--
Sort Day -->

            <xsl:if test="docReview/complete='0'">
               <tr>
                  <td><xsl:value-of select="title"/></td>
                  <td><xsl:value-of select="version"/></td>
                  <td><xsl:value-of select="docReview/dueDate"/></td>
                  <td><xsl:value-of select="adjudication/date"/></td>
                  <td><xsl:value-of
select="docReview/commentTemplateFile"/></td>
               </tr>

            </xsl:if>
         </xsl:for-each>
      </table>

      <br/>
      <!-- Display all documents in the library in table format.  The
documents
           will be grouped by category (IRS, SSS, SRS, etc), then
grouped by
           document name, and then sorted by version number. -->

      <!-- This loop selects the unique categories and loops through
them
           iteratively making a table from each category -->
      <xsl:for-each select="document[count(. |
key('documentsByCategory', category)[1]) = 1]">
         <xsl:sort select="category"/>
            <br/>
            <table border ="1">
               <caption><xsl:value-of select="category"/>
Documents</caption>
               <tr>
                  <th>Title</th>
                  <th>Version</th>
                  <th>Review Comments/Response File</th>
               </tr>

               <!-- This loops through all of the documents in each
category -->
               <xsl:for-each select="key('documentsByCategory',
category)">
                  <xsl:sort select="title"/>
                  <tr>
                    <td><xsl:value-of select="title"/></td>
                    <td><xsl:value-of select="version"/></td>
                    <!-- <td><xsl:value-of
select="docReview/reviewCommentsFile"/></td> -->
                  </tr>
               </xsl:for-each>
            </table>

      </xsl:for-each>
   </xsl:template>

</xsl:stylesheet>

Could someone please help me out with grouping both on category and
title?  I have looked through the archive postings most of the day and I
still cannot figure out how this works.  I am terribly confused and
cannot find a lot of information on this on the web.

Thanks for the help,
Rob Hix

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.