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

Please help with Grouping & sorting ! ;-(

Subject: Please help with Grouping & sorting ! ;-(
From: "Khan, Amir" <amkhan@xxxxxxxxxx>
Date: Tue, 3 Sep 2002 17:26:37 +0100
previous sibling sorted
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


Current Thread

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.