The problem is that although it is grouped by grade, I need to group by
grade and tutor. Here is the approach I have been trying:
<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>
This is a condensed version, but it is the gist of what I have been
trying to do.
I am not looking for anyone to do this for me... I just don't understand
some of the grouping methods. I have read a few of the faq's and
helpful sites, but do not see anything that applies like this. Maybe I
am overcomplicating it though.
-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of
Wendell Piez
Sent: Friday, January 09, 2004 6:58 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Re:
Hi,
At 06:17 PM 1/9/2004, you 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?
They are already grouped by grade, so it appears you just need to group
students by tutors.
Grouping in XSLT 1.0, while it is not trivial, is well-documented (in
part
because it's not trivial), and you will find a wealth of resources on
line
explaining various techniques of doing it, including both on the XSL FAQ
(http://www.dpawson.co.uk/xsl/sect2/sect21.html) and everyone's favorite
helper site for XSLT grouping,
http://www.jenitennison.com/xslt/grouping/index.html.
Since you haven't said exactly what's got you stuck here, it's
impossible
to offer more specific advice, short of simply writing the code to do
this.
And that really wouldn't be much help, would it? While the list has an
interest in helping and encouraging you to learn XSLT, we don't have
much
interest in doing the job for you....
If you have a more specific or focused question on a point you find
confusing, please don't hesitate to ask. (Oh, and use a subject line
next
time too. :-)
Cheers,
Wendell
======================================================================
Wendell Piez
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list