RE: [xsl] Please help with Grouping & sorting ! ;-(

Subject: RE: [xsl] Please help with Grouping & sorting ! ;-(
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Tue, 3 Sep 2002 18:31:20 +0100
Read up on grouping at http://www.jenitennison.com/xslt/grouping

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Khan, Amir
> Sent: 03 September 2002 17:27
> To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
> Cc: Khan, Amir
> Subject: [xsl] Please help with Grouping & sorting ! ;-(
> 
> 
> Hi,
> 
> I have some XML of the form
> 
> <catalogue>
> 	<item price="1" category="gold">this is a bracelet</item>
> 	<item price="5" category="Silver">this is a silver watch</item>
> 	<item price="1" category="gold">this is a ring</item>
> 	<item price="0" category="platinum">this is a platinum 
> time piece</item> </catalogue>
> 
> 
> What I want to do is make a webpage like :-
> 
> Platinum
> 	this is a platinum timepiece
> Gold
> 	* this is a bracelet
> 	* this is a ring
> Silver
> 	* this is a silver watch
> 
> 
> I've managed to group & sort the data. My problem is 
> detecting when a new category appears and then spitting out 
> the label as a Heading.
> 
> I have something like :-
> 
>   <xsl:variable name="previousCategory">XXX</xsl:variable>
>   <xsl:for-each select="item">
>         <xsl:sort select="@price" data-type="number" 
>                   order="ascending"/>  
>           <!-- If the category has changed then this is a new 
>                "heading"
>           -->
>           <xsl:if test="@category[.!=$previousCategory]">
> 		<xsl:if test="@category[.!="XXX"]">
> 		 	<!-- no more than a </UL> -->
>                 <xsl:call-template name="end_of_group"/>
>             </xsl:if>
> 		<!-- new group = spit out new heading 
> 		 	no more than a <UL> followed by the @category
> 		-->
>             <xsl:call-template name="new_group"/>
>           </xsl:if>
> 	  <xsl:call-template name="item_element"/>
>           <!-- Store this Category for the next iteration
> 		   so we know if we should display a new heading
> 	     -->
>           <xsl:variable name="previousCategory" select="@category"/>
>     </xsl:for-each>
> 
>     <xsl:template name="item_element">
>     <LI>
>         <xsl:apply-templates/>
>     </LI>
>     </xsl:template>
> 
> 
> What I actually see is :-
> 
> Platinum
> 	this is a platinum timepiece
> Gold
> 	* this is a bracelet
> Gold
> 	* this is a ring
> Silver
> 	* this is a silver watch
> 
> Its ordered correctly BUT it does'nt realise that its already 
> displayed a heading (eg Gold) and its not supposed to show it 
> again until it changes to Silver. I think its because the 
> variable previousCategory is write-once but then how do I 
> keep track of the previously displayed attribute "category" 
> in the previous sibling in the SORTED node set?
> 
> Help! ;-((
> 
> Amir
> 
> --------------------------------------------------------------
> ----------------
> This message is intended only for the personal and 
> confidential use of the designated recipient(s) named above.  
> If you are not the intended recipient of this message you are 
> hereby notified that any review, dissemination, distribution 
> or copying of this message is strictly prohibited.  This 
> communication is for information purposes only and should not 
> be regarded as an offer to sell or as a solicitation of an 
> offer to buy any financial product, an official confirmation 
> of any transaction, or as an official statement of Lehman 
> Brothers.  Email transmission cannot be guaranteed to be 
> secure or error-free.  Therefore, we do not represent that 
> this information is complete or accurate and it should not be 
> relied upon as such.  All information is subject to change 
> without notice.
> 
> 
> 
>  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