|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Grouping with second choice
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
|
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
|

Cart








