RE: [xsl] Sorting the second level

Subject: RE: [xsl] Sorting the second level
From: TSchutzerWeissmann@xxxxxxxxxxxxxxxx
Date: Fri, 9 Nov 2001 12:27:09 -0000
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="/">
        <style type="text/css">
          .Lang {}
          .manf { text-indent:1cm;}
          .prod { text-indent:2cm;}
   <xsl:template match="courses">
	<!-- 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"/>
	<span class="Lang">
	<xsl:value-of select="lang"/>

	<!-- 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 =
		<span class="manf">
		 <xsl:value-of select="manufacturer"/>
		<span class="prod">
		<xsl:value-of select="title"/>

 XSL-List info and archive:

 XSL-List info and archive:

Current Thread