This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Finding the lowest 'price' element
- From: Dimitre Novatchev <dnovatchev at yahoo dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Sat, 4 May 2002 22:07:39 -0700 (PDT)
- Subject: [xsl] Re: Finding the lowest 'price' element
- Reply-to: xsl-list at lists dot mulberrytech dot com
> 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