Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

for-each

Syntax

Description

Include a looping mechanism that repeats script processing for each XML element in the specified node set or each value in the integer set.

If the argument is an XPath expression, the element nodes are selected by the value of the XPath expression. If the argument is an integer set, the iteration operator (...) generates a sequence of nodes with the value of each integer between the left and right operands. If the left operand is greater than the right operand, the numbers are generated in decreasing order. For each iteration, the contents are then evaluated, processed according to the instructions contained in the for-each code block.

Attributes

for-each expression

XPath expression that selects the nodes to be processed.

max

Integer or variable that defines the end value of the integer sequence. If the end value is less than the start value, the numbers are generated in decreasing order.

min

Integer or variable that defines the starting value of the integer sequence. If the start value is greater than the end value, the numbers are generated in decreasing order.

SLAX Example

The following code iterates over each chassis-sub-module element that has a part-number child element equal to 750-000610. For each match, the script outputs a <message> element with the name of the module and the name and description of the submodule.

The following code iterates over the integers 1 through 3. For each iteration, the code block generates an <item> element, which contains the attribute item-number with a value equal to the current integer value of the set.

Release Information

Statement introduced in version 1.0 of the SLAX language.

Support for iteration operator (...) added in version 1.1 of the SLAX language, which is supported in Junos OS Release 12.2 and later releases.