xsl-list
[Top] [All Lists]

Re: Using an index with a sorted list of elements

2003-03-18 23:56:39
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="//*[(_at_)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



<Prev in Thread] Current Thread [Next in Thread>