This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]