Iterate through the specified list and executes specified body logic for each item. Result is the list of processed bodies.

Syntax

<loop item="item_var_name"
      index="index_var_name"
      maxloops="max_loops"
      filter="list_filter"
      empty="empty">
    <list>
        body as list value
    </list>
    <body>
        body for each list item
    </body>
</loop>

Attributes

Name Required Default Description
item no Name of the variable that takes the value of current list item.
index no Name of the index variable, initial value for the first loop is 1.
maxloops no Limits number of iterations. There is no limit if it is not specified.
filter no Expression for filtering iteration list. It consists of arbitrary number of restrictions separated by comma. There are the following types of restrictions:
  • [n]-[m], for specifying index range, for example: 3-6, -5.
  • [n][:][m], for specifying sublist starting at index n and including items at indexes n+m, n+2*m, n+3*m, ..., for example 1:2 for all odd, 2:2 for all even.
  • unique, that removes duplicates from list comparing string values of list items.
Valid filter which is combination of allowed restrictions is for example: 1-20,1:2,unique.
empty no no Equal to surrounding body by empty element, producing empty result of iteration.

Example

<loop item="link" index="i" filter="unique">
    <list>
        <xpath expression="//img/@src">
            <html-to-xml>
                <http url="http://www.yahoo.com"/>
            </html-to-xml>
        </xpath>
    </list>
    <body>
        <file action="write" type="binary" path="images/${i}.gif">
            <http url="${sys.fullUrl('http://www.yahoo.com', link)}"/>
        </file>
    </body>
</loop>

Loop iterates over the all unique image URLs from www.yahoo.com and for each URL downloads the image and stores it to the file system.