RTML Operator “ACCUMULATE”
In an RTML Template, the “ACCUMULATE” operator looks like:
ACCUMULATE result_var nil iter_var nil result_init nil sequence nil
This operator accumulates certain values in result_var. At the beginning of iteration, result_var holds the value of the result_init variable. Sequence holds the list of objects (for example: the list of items). The ACCUMULATE operator takes elements from this list and passes them into iter_var variable one by one. Then the ACCUMULATE operator evaluates the expression assigned within it and passes the result to result_var.
Let’s look at the following example:
WITH= variable maximum-price value ACCUMULATE result_var maxprice iter_var item result_init MINNUM sequence @contents MAXIMUM maxprice WITH-OBJECT item ELEMENT position 0 sequence OR @price @sale-#price WITH= variable minimum-price value ACCUMULATE result_var minprice iter_var item result_init MAXNUM sequence @contents MINIMUM minprice WITH-OBJECT item ELEMENT position 0 sequence OR @price @sale-price TEXT GRAB "price from $" TEXT minimum-price " to $" TEXT maximum-price
In this example, we are defining the minimum and maximum price for the products that is in the listing page’s built-in property contents. For this purpose, we are also using RTML operators MINNUM and MAXNUM. They hold the minimum and maximum numbers in the Yahoo store system. If we want to get the minimum price, then we have to determine the maximum value first in result_init , if we want to obtain the maximum item price, then we have to determine the minimum value first in result_init. Within the ACCUMULATE operator we compare item_var and item price. Then the result will passed to item_var
This entry was posted on Sunday, March 18th, 2012 at 4:26 pm and is filed under Description of RTML Operators. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.