This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

More efficient max() algorithm (Was: Re: Re: Max value from a table )


> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";;>
>   <xsl:output indent="yes"/>
> 
> <xsl:variable name="max">
>     <xsl:for-each select="/table/row/col">
>         <xsl:sort select="text()" data-type="number" order="descending"/>
>         <xsl:if test="position() = 1">
>            <xsl:value-of select="text()"/>
>        </xsl:if>
>    </xsl:for-each>
> </xsl:variable>

This algorithm, as the one currently presented in the XSLT-FAQ, is O(N * Log2(N))
complex.
There exists an O(N) algorithm -- look for it in the Jan/Feb threads of this group
or in the generic templates download at vbxml.com.
This algorithm uses simple recursion and may crash some XSLT processors.

Another O(n) algorithm, which might be the fastest on a parallel processor
environment and which has minimum recursion depth -- this is a Divide and Conquer
algorithm for max().

Cheers,
Dimitre Novatchev.




__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]