The Set Value activity within Process Management orchestrations uses xPath for building expressions. And xPath has some
quirks features that can frustrate developers who are not used to it.
One thing that can be confusing is how to iterate through XML collections. The problem is caused by the fact that xPath interprets all variables as strings unless they are coerce to some other type. And this coercion can happen automatically in some circumstances.
In this case, the variable @i is treated as a number because it is being added to another number:
/process_data/@i = /process_data/@i + 1 // this performs addition and increments @i by 1
But when used as an xPath reference variables are treated as strings:
/process_data/@i = 1 /process_data/myXML/topElement/childElement[/process_data/@i] // this will return the first item /process_data/@i = 20 /process_data/myXML/topElement/childElement[/process_data/@i] // this returns the first item, too!
When used a reference, always coerce variables to be a Number:
/process_data/@i = 20 /process_data/myXML/topElement/childElement[Number(/process_data/@i)] // this returns the 20th item