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

RE: calculate unique items in xsl

Subject: RE: calculate unique items in xsl
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Fri, 11 Oct 2002 10:30:54 +0100
xslt calculate
> 
> Thanks for your help in my previous post!  Given the below 
> xml,how can I get 
> the
> the number of unique warehouse codes?  Do I need to use <xsl:key>?

Removing duplicates is the same problem as grouping, so look up
"grouping" in your favourite textbook or FAQ site.

With XSLT 1.0 there are basically two techniques. 

Simple problems on small documents (like your example) can be solved
using

  count(item[not(whcode = preceding-sibling::item/whcode)])

More complex problems, or problems on larger documents, require
Muenchian grouping using xsl:key, as described at
http://www.jenitennison.com/xslt/grouping

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

> 
> <inventory>
> <item>
> <warehousecode>BA</warehousecode>
> <item>bolt</item>
> <quantity>34</quantity>
> </item>
> <item>
> <warehousecode>BA</warehousecode>
> <item>nail</item>
> <quantity>50</quantity>
> </item>
> <item>
> <warehousecode>AC</warehousecode>
> <item>tack</item>
> <quantity>5</quantity>
> </item>
> <item>
> <warehousecode>BA</warehousecode>
> <item>hammer</item>
> <quantity>10</quantity>
> </item>
> <item>
> <warehousecode>AD</warehousecode>
> <item>screwdriver</item>
> <quantity>60</quantity>
> </item>
> <item>
> <warehousecode>AB</warehousecode>
> <item>wrench</item>
> <quantity>13</quantity>
> </item>
> </inventory>
> 
> 
> Desired output:
> 
> Number of unique warehouse codes:  4
> 
> Thanks for helping an xsl newbie!!
> 
> RJ
> 
> 
> _________________________________________________________________
> Join the world?s largest e-mail service with MSN Hotmail. 
> http://www.hotmail.com
> 
> 
>  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

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.