[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Help with multiple key grouping...
At 2007-11-19 15:11 -0600, Hix, Robert W CIV NSWCDD, Q45 wrote:
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: I note you are using stylesheet association, as if you were browsing this document. That would imply that the version of XSLT you are using is 1.0 since browsers these days only support 1.0. 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. Here you indicate XSLT 2.0. Your answer would be a lot easier if you really could use 2.0, but so far I see you are only using 1.0 approaches to grouping. I'll continue answering as if you need to use XSLT 1.0, but if you could use 2.0 it would be a lot easier. 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. You need to do grouping on a sub-document basis. When using XSLT 1.0, I typically do sub-document grouping using variables rather than using keys because keys are specified document-wide. In the stylesheet below you'll see that within each category I put all of the documents of the category into a variable, and then I do the uniqueness grouping out of the variable instead of out of the key. This way the grouping acts on only a part of the document and not the entire document. It can be done with keys, but involves standing on your hands and holding your tongue in a certain position. While the variable-based grouping method for XSLT 1.0 more easily accommodates both sub-document grouping and supra-document grouping. And if you did have XSLT 2.0 available, your stylesheet would be a lot easier as it wouldn't need either keys or variables to do what you need. I hope this helps. . . . . . . . . . . . Ken <?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:variable name="docs" select="key('documentsByCategory',category)"/> <xsl:for-each select="$docs"> <xsl:sort select="title"/> <xsl:if test="generate-id(.)= generate-id($docs[title=current()/title][1])"> <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:if> </xsl:for-each> </table> </xsl:for-each> </xsl:template> </xsl:stylesheet>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|