For Each Tag

The For Each Tag action loops through a group of tags. In each iteration, the appropriate tag is marked as a named tag.

Most often, the loop should loop from the beginning to the end, such as looping through all the <tr>-tags of a table. However, it is also possible to configure the For Each Tag action to loop through only some of the tags, such as the last n tags in a sequence.

The For Each Tag action is similar to the For Each Tag Path action. The main difference is that the For Each Tag action only finds the immediate children of the found tag, whereas the For Each Tag Path action searches the entire subtree.

Properties

The For Each Tag action can be configured using the following properties:

Tag

The name of the tags to loop through, for example, tr.

Classes to Include

Specify the classes of nodes to include in the result. Conjunction (logical AND) is denoted by space and disjunction (logical or) is denoted by |. Conjunction takes precedence over disjunction, for example class1 class2 specifies the nodes that are both of class1 and class2, class1 | class2 | class3 specifies the nodes that are either of class1, class2, or class3, whereas class1 class2 | class3 class4 specifies the nodes that are either both of class1 and class2 or both of class 3 and class4.

Classes to Exclude

Specify the classes of nodes to exclude from the result. Conjunction (logical AND) is denoted by space, disjunction (logical or) is denoted by |, and the explicit absence of classes is denoted by $. Conjunction takes precedence over disjunction, for example class1 class2 specifies the nodes that are both of class1 and class2, class1 | $ specifies the nodes that are either of class1 or of no class at all, class1 | class2 | class3 specifies the nodes that are either of class1, class2, or class3, whereas class1 class2 | class3 class4 specifies the nodes that are either both of class1 and class2 or both of class 3 and class4.

First Tag Number

The number of the first tag to include in the loop. The number can be specified to count either forward from the first tag, or backward from the last tag.

Last Tag Number

The number of the last tag to include in the loop. The number can be specified to count either forward from the first tag, or backward from the last tag.

Tag Number Increment

Make the loop skip tags. For example, if an increment of 2 is specified, the loop will skip every second tag

Loop Backwards

Select that the loop should loop through the matching tags in reverse order. Please note that the loop will go through exactly the same tags as if it were looping forward just in reversed order. This means that the First Tag Number is referring to first tag in the selection of tags to loop over and not the first tag visited when looping (actually it will be the last).

Number of Tags to Include Before

The number of tags (of the same name) before the named tag to include in each output.

Number of Tags to Include After

The number of tags (of the same name) after the named tag to include in each output.

Tag Name

Has two options, Auto or Named.Auto gives the tag a name which is number. The first Auto-numbered tag will have number 1, the next number 2 etc. Note that the number may change if additional Auto-numbered tags are inserted before this step (on the same page).Named gives the tag a fixed and explicitly stated name, which has several advantages:

  • It is easier to remember what the named tag identifies if it has a well-chosen name
  • An explicitly named tag is not affected if another named tag is inserted before it
  • If you use the same name again in Set Named Tag, the name will simply be made to refer to the new tag (useful for stateful in-page looping)
Keep Existing Named Tags

If this option is selected, existing named tags are kept along with the named tag marking the result of each iteration. If this option is not selected, existing named tags are removed, and each output state will only contain the named tag marking the result of the iteration.

Example

Consider this found tag:

<tbody>
  <tr>...
  <tr>...
  <tr>...
  <tr>...
  <tr>...
</tbody>
      
With Tag Name set to "tr", First Tag Number set to 0 (From First), andLast Tag Number set to 1 (From Last), the For Each Tag action will loop through <tr>-tags 0, 1, 2, and 3. In each iteration, the named tag set by the action will be the appropriate <tr>-tag as shown below:
Iteration Named Tag

1

<tr>-tag 0

2

<tr>-tag 1

3

<tr>-tag 2

4

<tr>-tag 3