[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Sorting the second level

Subject: RE: Sorting the second level
From: TSchutzerWeissmann@xxxxxxxxxxxxxxxx
Date: Fri, 9 Nov 2001 12:27:09 -0000
bylang
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


Current Thread
  • Sorting the second level
    • Ivo - Thu, 8 Nov 2001 18:50:44 -0500 (EST)
      • <Possible follow-ups>
      • TSchutzerWeissmann - Fri, 9 Nov 2001 07:40:12 -0500 (EST) <=

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.