xsl-list
[Top] [All Lists]

RE: need help with MAX and MIN functions (if they exist)

2003-07-21 08:09:21
I'd like to select the max (and 
min) closing price for each equity. I've been 
searching through the zvon.org xslt reference and i 
could'nt find max or min functions. Does anyone know 
how to do this? 
 
Use the "maximum" and "minimum" templates from FXSL. 

True enough Demitre, but as you are already using vendor:node-set you may as 
well
use exsl's max() and min() functions... 

I'm all for using FXSL, but in the case of simple exsl functions, why not use 
those?

First a small correction: for XSLT 1.0 the latest FXSL version 1.2 uses
ext:node-set(), where the prefix "ext" is associated with 
"http://exslt.org/common";

FXSL for XSLT 2.0 does not use any extension functions and does not need 
porting or
separate implementation for a particular XSLT 2.0 processor like EXSLT will 
need.

The question should be more properly formulated like this: why one would choose 
to
use FXSL's minimum() and maximum() over EXSLT's min() and max() and vice versa 
or
more generally why and in what cases one would choose the FXSL's functions over 
the
EXSLT's functions and vice versa.

The answer is that this depends on the needs of the user. 

In FXSL minimum() and maximum() are higher-order functions. They accept a 
comparison
function as a parameter. This makes them usable in a variety of situations 
where a
simple min() or max() function will not be applicable.

One group of examples is where the maximum should be produced for values that 
are
calculated from each node -- FXSL provides a single, linear, one-pass solution 
to
this problem.

The use of a comparison function passed as parameter makes it possible to 
calculate
the minimum/maximum even in the extreme case for such types of values, which 
cannot
be directly converted to numbers.


It is generally incorrect to compare a library of higher order functions to a
library of non-higher-order functions, as the former is much more powerful and 
can
have huge scope, and can provide solutions (new functions) to an unlimited 
number of
problems, not known in advance.

Take for example such generic functions as foldl and foldr.

One can create an indefinite number of new, useful list-processing functions 
just by
feeding foldl and foldr with different parameters -- functions and initial 
values.

  sum = foldl (+) 0

  product = foldl (*) 1

  someTrue = foldl or false

  allTrue = foldl and true

  maximum = foldl1 max

  minimum = foldl1 min

  append as bs = foldr (:) bs

  map f = foldr ((:) . f) []

  . . . . . . . . . . . . . . .

and so on. The list of such functions is unlimited.

Therefore, if I need to solve just a single problem I might use a simple set of
non-higher-order functions if this set happens to provide a solution. If it 
does not
happen to provide a solution I will be out of luck.

On the other side, if I need a powerful, generic toolkit,which does not rely on
extension functions, and which when parameterised will provide solutions to a 
huge,
unanticipated class of problems, then I will choose the library of generic
higher-order functions, that provides exactly these capabilities.






=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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