[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: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Sat, 4 May 2002 22:07:39 -0700 (PDT)
low price books
> 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?

Here's the solution using FXSL:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
   <xsl:import href="maximum.xsl"/>
   
   <xsl:output method="text"/>

    <xsl:template match="/">
      <xsl:call-template name="maximum">
        <xsl:with-param name="pList" select="/books/book/price"/>
      </xsl:call-template>
    </xsl:template>
</xsl:stylesheet>


When this transformation is applied on the following source xml:

<books>
  <book>
    <price>20</price>
  </book>
  <book>
    <price>10</price>
  </book>
  <book>
    <price>30</price>
  </book>
  <book>
    <price>15</price>
  </book>
</books>

the result is:

30


Cheers,
Dimitre Novatchev.


__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

 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.