[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: Thorsten Liebig <liebig@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 17 Aug 2001 12:02:30 +0200
studio keys choi
Jeni Tennison wrote:


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:


Thanks for the hint. But what I intend to do, is to divide the students
according to there choices *and* additional constraints like maximum group
size. So, whenever a first choice cannot be fulfilled due to group size
reasons the second choice should be taken into account. My problem is
(I think), that all those solutions do not apply in which the group tags
are created on the fly (like in the solution below) because it may happen
that a student has to be divided in a group which hasn't been created, yet.
Concrete, having a maximal group size of 3, the students of my example file
should be classified as follows:

<group1>
   <student> ... A ... </student>
   <student> ... B ... </student>
   <student> ... C ... </student>
</group1>
<group2>
   <student> ... D ... </student>
   <student> ... E ... </student>
   <student> ... F ... </student>
</group2>

- Thorsten


<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


--
_____________________________________________________________
Thorsten Liebig              Abteilung Künstliche Intelligenz
Tel.: +49 731 502 4207                Fakultät für Informatik
Fax.: +49 731 502 4119                        Universität Ulm


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.