Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] First Element in Sorted List

From: "Michael Kay" <mike@------------>
To:
Date: 6/2/2005 3:08:00 AM
> My process needs to take action on the first element in a list of 
> elements where the logic to determine first is the lowest 
> numeric value 
> of the sortorder attribute.  I don't believe there is a 
> one-line way to 
> do this - I believe the entire list must be sorted, and then the 
> position of each element after sort compared to determine if 
> it is first.

Yes. Even in XSLT 2.0 this may be the best approach. 2.0 offers min/max
functions, but they give you the highest/lowest value, not the node having
that value.

Writing a recursive template/function might give you better performance than
sorting (linear rather than n*log(n)). 

There is a one-line solution: $x[not($x/@sortorder < @sortorder)] but it's
quite likely to have poor (quadratic) performance.

You could consider using EXSLT math:highest() or math:lowest().

Or I'm sure there's something in Dimitre's box of tricks called FXSL.

Michael Kay
http://www.saxonica.com/

> 
> Is there a shorter/less expensive way to code the following
> 
> <xsl:for-each select="item">
>    <xsl:sort select="@sortorder" data-type="number" />
>    <xsl:if test="position() = 1">
>      <!-- this is the first element in the sorted list -->
>    </xsl:if>
> </xsl:for-each>
> 
> I searched and found examples using this technique, but 
> nothing really 
> saying that this was the best or only approach.
> 
> Thanks in advance,
> 
>     -John


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent