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

RE: Finding the lowest 'price' element

Subject: RE: Finding the lowest 'price' element
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Sun, 5 May 2002 18:20:02 +0100
xpath find minimum value
There are basically three approaches to finding a minumum value:

(1) use a recursive template to visit each of the nodes, keeping track of
the minimum value found so far
(2) sort the nodes and select the first/last one in the sorted set
(3) use an XPath expression to find the node whose value is less than every
other value (someone posted this solution for you).

The interesting thing is that they have very different scaleability. (1)
visits each node once so it has O(n) performance; (2) does a sort so it has
O(n log n) performance, (3) if implemented crudely will compare every node
with every other, so it potentially has O(n*n) performance (but processors
may be able to optimize it). (However, although (1) performs in linear time,
it may use a lot of memory depending on how well recursion is implemented).

Of course if you use Dimitre's FXSL library or the EXSLT max() and min()
extension functions then you don't have to decide between these algorithms,
someone else has already done the hard work for you.

In XPath 2.0 there are max() and min() functions in the core function

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 tinku
> Sent: 05 May 2002 00:15
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Finding the lowest 'price' element
> Hi all,
>     I have several book elements, in which each book element has a
> 'price' child element.
>    <book>
>      <price>20</price>
>    </book>
>    <book>
>      <price>10</price>
>    </book>
>      .
>      .
>      .
> Now, I need to find the lowest 'price' element using XSLT?
> One solution which i think is:
>     1. first sort the above xml document using <xsl:sort>
>     2. Now we get a new tree with all the price elements in
> ascending order.
>     3. Now we will find the first 'price' element which is the
> lowest using the "position()" function.
>    Here the result tree is again fed with a new stylesheet(to find
> the first position), to the xslt processor.
> Is there any better solution than this?
> Thanks in advance!!
> _________________________________________________________
> Click below to visit monsterindia.com and review jobs in India or
> Abroad
> http://monsterindia.rediff.com/jobs
>  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


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.
First Name
Last Name
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.