This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Sorting the second level
- To: xsl-list at lists dot mulberrytech dot com
- Subject: RE: [xsl] Sorting the second level
- From: TSchutzerWeissmann at uk dot imshealth dot com
- Date: Fri, 9 Nov 2001 12:27:09 -0000
- Reply-To: xsl-list at lists dot mulberrytech dot com
Ivo wrote
>I am using the following statements to create the Lang Titles (ie. French,
>English, etc...):
>
><xsl:if test="not(preceding-sibling::course/lang = lang)">
><tr><xsl:value-of select="lang" /></tr>
>
>I've also done the same with manufacturer:
Hello Ivo
This is really a grouping problem, not just a question of creating titles in
the right place, because you want to sort your <course>s into language
groups, then sort within those language groups by manufacturer.
So you need a way of making the language groups - xsl:key.
Using <xsl:key name="bylang" match="course" use="lang"/> you can access a
node-set of <course> nodes using their <lang> element, so
key('bylang','English') gives you all the English <course>s.
Jeni's site has some examples of how to do this (Muenchian grouping), which
I used.
Hope the following helps,
Tom Weissmann
<xsl:key name="bylang" match="course" use="lang"/>
<xsl:template match="/">
<html>
<head>
<style type="text/css">
.Lang {}
.manf { text-indent:1cm;}
.prod { text-indent:2cm;}
</style>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="courses">
<table>
<!-- just get the first of each language group -->
<!-- the union of the first of a set and itself can only have 1
member -->
<xsl:for-each select="course[count(. | key('bylang',lang)[1])=1]">
<xsl:sort select="lang"/>
<tr>
<span class="Lang">
<xsl:value-of select="lang"/>
</span>
</tr>
<!-- now use the key to get the whole group with the same <lang> as
the current node -->
<xsl:for-each select="key('bylang',lang)" mode="lang"/>
<xsl:sort select="manufacturer"/>
<!-- use Ivo's method to do the manufacturer row - you could use
another key --> <xsl:if test="not(preceding-sibling::course/manufacturer =
manufacturer)">
<tr>
<span class="manf">
<xsl:value-of select="manufacturer"/>
</span>
</tr>
</xsl:if>
<tr>
<span class="prod">
<xsl:value-of select="title"/>
</span>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</xsl:template>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list