|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Grouping with second 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() <= 3">
<xsl:copy-of select="."/>
</xsl:if>
<xsl:if test="position() > 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
|
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








