Re: [xsl] Using an index with a sorted list of elements

Subject: Re: [xsl] Using an index with a sorted list of elements
From: bix_xslt@xxxxxxxxxxx
Date: Wed, 19 Mar 2003 00:56:39 -0600
Hugh,

> I have a number of elements, similar to <element @value/>
> I want to find the element that has the biggest value of "value" less
> than a value $upperBound.

I would try to think about it more like this.  Let me sort the values first,
and then grab the value I want (i.e. small easy steps will get me there
sooner).

        <x:for-each select="//*[@value &lt; $upperBound]">
            <x:sort data-type="number" order="descending" select="@value"/>
               <x:if test="position() = 1"><x:value-of
select="@value"/></x:if>
          </x:for-each>

To break it down, this selects every node that has a @value less than the
upper bound, and then sorts based on that value attribute in a descending
order.  Then, it selects the first one.  There's probably another, slicker
way to do this with the [1], but I think this will work for you.

bix



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread