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

Grouping with second choice

Subject: Grouping with second choice
From: Thorsten Liebig <liebig@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 31 Jul 2001 11:22:02 +0200
xsl if choice
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?

Thorsten

----------------------- classification.xsl
--------------------------------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml"/>

<xsl:key name="students-by-firstchoice" match="Student"
use="FirstChoice"/>

<xsl:template match="Course">
  <xsl:element name="Classification">
 <xsl:for-each select="Student[count(. | key('students-by-firstchoice',
FirstChoice)[1]) = 1]">
   <xsl:sort select="FirstChoice" />
         <xsl:element name="{FirstChoice}">
          <xsl:for-each select="key('students-by-firstchoice',
FirstChoice)">
      <xsl:sort select="RegistrationDate" />
              <xsl:if test="position() &lt;= 3">
           <xsl:copy-of select="."/>
        </xsl:if>
        <xsl:if test="position() &gt; 3">
           <!-- use second choice for grouping -->
        </xsl:if>
          </xsl:for-each>
        </xsl:element>
      </xsl:for-each>
   </xsl:element>
</xsl:template>

</xsl:stylesheet>

----------------------- students.xml -------------------------------
<?xml version="1.0" encoding="ISO-8859-1" ?>
<Course>
   <Student>
      <RegistrationDate>20010725</RegistrationDate>
      <FirstChoice>Group1</FirstChoice>
      <SecondChoice>Group2</SecondChoice>
      <Name>B</Name>
   </Student>
   <Student>
      <RegistrationDate>20010724</RegistrationDate>
      <FirstChoice>Group1</FirstChoice>
      <SecondChoice>Group2</SecondChoice>
      <Name>A</Name>
   </Student>
   <Student>
      <RegistrationDate>20010726</RegistrationDate>
      <FirstChoice>Group1</FirstChoice>
      <SecondChoice>Group2</SecondChoice>
      <Name>C</Name>
   </Student>
   <Student>
      <RegistrationDate>20010723</RegistrationDate>
      <FirstChoice>Group2</FirstChoice>
      <SecondChoice>Group1</SecondChoice>
      <Name>E</Name>
   </Student>
   <Student>
      <RegistrationDate>20010722</RegistrationDate>
      <FirstChoice>Group2</FirstChoice>
      <SecondChoice>Group1</SecondChoice>
      <Name>D</Name>
   </Student>
   <Student>
      <RegistrationDate>20010727</RegistrationDate>
      <FirstChoice>Group1</FirstChoice>
      <SecondChoice>Group2</SecondChoice>
      <Name>F</Name>
   </Student>
</Course>


 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.