Subject: [xsl] Grouping with second choice From: Thorsten Liebig <liebig@xxxxxxxxxxxxxxxxxxxxx> Date: Tue, 31 Jul 2001 11:22:02 +0200 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] HTML link dynamically for, Jarno . Elovirta | Thread | Re: [xsl] Grouping with second choi, Jeni Tennison |
RE: [xsl] HTML link dynamically for, Jarno . Elovirta | Date | RE: [xsl] two columns in a table fr, Michael Kay |
Month |