Sample XML:
<employees>
<employee>
<name>NAME1</name>
<age>25</age>
</employee>
<employee>
<name>NAME2</name>
<age>30</age>
</employee>
<employee>
<name>NAME3</name>
<age>35</age>
</employee>
</employees>
We can use "While" Activity for looping through multiple
1. Initialize a simple int "counter" variable and set the value = 0
2. Count the number of employee nodes in employees root node using,
ora:countNodes("employees/employee")
[Note: Use BPEL Expression builder to get the XPath Expression but remember to delete bpws:getVariableData from the expression because we are not looking for data but only number of nodes]
3. Loop through each of the employee node and check if the <age> is greater than 26 as:
bpws:getVariableData('employees','part',"employee[position()=bpws:getVariableData('counter')]")
4. Increment the counter and you will be able to a access all the employee data dynamically.
Things to remember:
1. In BPEL, the index starts with 1 and not 0 so make sure the "counter" value starts from 1 and not 0.
2. Whereever in the XPath you are accessing a variable inside a variable such as, { "employee[position()=bpws:getVariableData('counter')]" } use double quotes for outside variable and single quotes for inside variable
3. Use position() function as shown above