xsl-list
[Top] [All Lists]

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

2014-04-10 14:55:42
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(_at_)gmail(_dot_)com> wrote:
On Thu, Apr 10, 2014 at 5:20 AM, David Rudel <fwqhgads(_at_)gmail(_dot_)com> 
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.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--