[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Grouping with second choice
Subject: Re: [xsl] Grouping with second choice From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Tue, 31 Jul 2001 14:12:15 +0100 |
Hi Thorsten, > I want to group students according to their online registration > which is exported to xml similar to the file attached below > (students.xml). Registration allows students to express a first and > a second choice for their exercise. Using the Muenchian Method is > appropriate for sorting with respect to a single key, but how do I > realize grouping with constraints, e.g. use the second choice if the > first cannot be fulfilled (group is full)? Any hints? With a second level group, you need a key that groups all the Student element by FirstChoice *and* SecondChoice. You can concatenate the two values together, using an appropriate separator (e.g. a semi-colon): <xsl:key name="students-by-first-and-second-choice" match="Student" use="concat(FirstChoice, ';' SecondChoice)" /> You need to access the first Students in each of these subgroups in a similar way as you do for the first group, so you would have something like: <xsl:template match="Course"> <Classification> <xsl:for-each select="Student[count(.|key('students-by-firstchoice', FirstChoice)[1]) = 1]"> <xsl:sort select="FirstChoice" /> <xsl:variable name="FirstChoice" select="FirstChoice" /> <xsl:element name="{$FirstChoice}"> <xsl:for-each select="key('students-by-firstchoice', $FirstChoice) [count(.|key('students-by-first-and-second-choice', concat($FirstChoice, ';', SecondChoice))[1]) = 1]"> <xsl:sort select="SecondChoice" /> <xsl:element name="{SecondChoice}"> <xsl:for-each select="key('students-by-first-and-second-choice', concat($FirstChoice, ';', SecondChoice))"> <xsl:sort select="RegistrationDate" /> <xsl:copy-of select="." /> </xsl:for-each> </xsl:element> </xsl:for-each> </xsl:element> </xsl:for-each> </Classification> </xsl:template> (You might want to use moded templates rather than lots of nested xsl:for-each elements to make things clearer.) I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Grouping with second choice, Thorsten Liebig | Thread | [xsl] Interpretting XSL..., Mulberry Technologie |
RE: [xsl] Use Xerces with Saxon?, Michael Kay | Date | [xsl] Interpretting XSL..., Mulberry Technologie |
Month |
Keywords