Re: [xsl] Preferred declarative approach for outputting tallies based on complex triggers

Subject: Re: [xsl] Preferred declarative approach for outputting tallies based on complex triggers
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Thu, 10 Apr 2014 12:55:02 -0700
Here is the shortest complete example that comes to mind:

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="text"/>
  <xsl:template match="/*">
    <xsl:sequence select="fold-left(*, (0,1), function($x,
$y){$x[1]+$y, $x[2]*$y})"/>
  </xsl:template>
</xsl:stylesheet>

When this transformation is applied on the following source XML document:

<nums>
  <num>01</num>
  <num>02</num>
  <num>03</num>
  <num>04</num>
  <num>05</num>
  <num>06</num>
  <num>07</num>
  <num>08</num>
  <num>09</num>
  <num>10</num>
</nums>

the correct result is produced (the pair of the sum and product of the
values of the <num> elements):

55 3.6288E6


Cheers,
Dimitre


On Thu, Apr 10, 2014 at 11:26 AM, Dimitre Novatchev
<dnovatchev@xxxxxxxxx> wrote:
> On Thu, Apr 10, 2014 at 5:20 AM, David Rudel <fwqhgads@xxxxxxxxx> wrote:
>> And similar information like the above that can then be brought
>> together at the end to give the results I want in a single pass.
>
>
> One can (and probably should) use a single call to a fold-XXXX
> function to achieve this.
>
> The "zero value" (which is also the intermediary accumulator), can be
> of any wanted structured type, so it can hold all wanted results at
> the same time.
>
> --
> Cheers,
> Dimitre Novatchev
> ---------------------------------------
> Truly great madness cannot be achieved without significant intelligence.
> ---------------------------------------
> To invent, you need a good imagination and a pile of junk
> -------------------------------------
> Never fight an inanimate object
> -------------------------------------
> To avoid situations in which you might make mistakes may be the
> biggest mistake of all
> ------------------------------------
> Quality means doing it right when no one is looking.
> -------------------------------------
> You've achieved success in your field when you don't know whether what
> you're doing is work or play
> -------------------------------------
> To achieve the impossible dream, try going to sleep.
> -------------------------------------
> Facts do not cease to exist because they are ignored.
> -------------------------------------
> Typing monkeys will write all Shakespeare's works in 200yrs.Will they
> write all patents, too? :)
> -------------------------------------
> I finally figured out the only reason to be alive is to enjoy it.



-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Current Thread