The approach I am taking with this has been to for-each the first
occurrence of every tutor in Grade node. I then for-each a key matching
all Students to based on each tutor. I keep trying to only limit the
key to the current grade, but I don't think it is working.
<xsl:key name="students-by-tutor" match="Grade/Students/Name"
use="Tutor"/>
<xsl:template match="School">
<xsl:for-each select="Grade">
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:template>
<xsl:template match="Grade">
<xsl:for-each select="Students/Student/Name[Tutor[not(. =
preceding::Tutor)]]">
<xsl:sort select="Tutor"/>
<xsl:variable name="gradeName"
select="ancestor::Grade/Name"/>
<xsl:for-each select=key('students-by-tutor ',
Tutor)[ancestor::Grade/Name = $gradeName]>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:for each>
</xsl:template>
What am I missing? The key doesn't seem to only return students in the
given grade. It returns all students in all grades for the tutor.
--- kakridge(_at_)bellsouth(_dot_)net wrote: > I have been
having a problem with grouping. If I
have:
<School>
<Grade>
<Students>
<Student>
<Name>Bob</Name>
<Tutor>Mary Smith</Tutor>
</Student>
<Student>
<Name>Joe</Name>
<Tutor>Mike Smith</Tutor>
</Student>
<Students>
<Name>Kindergarten</Name>
</Grade>
<Grade>
<Students>
<Student>
<Name>Ted</Name>
<Tutor>Mary Smith</Tutor>
</Student>
<Student>
<Name>Sammy</Name>
<Tutor>Mike Smith</Tutor>
</Student>
</Students>
<Name>First</Name>
</Grade>
</School>
How can I group each grade, and within each grade,
group all tutors with
their students?
Something like this:
Grade: Kindergarten
Tutor: Mary Smith
Students: Bob,.,.,.
Grade: Kindergarten
Tutor: Mike Smith
Students: Joe,.,.,.
Grade: First
Tutor: Mary Smith
Students: Ted,.,.,.
etc.
Thanks
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list