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

Re: Grouping with second choice

Subject: Re: Grouping with second choice
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 31 Jul 2001 14:12:15 +0100
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


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.