Ranjith Ravindran
Ranjith Ravindran

Reputation: 43

Set dynamic variabe in the Datapower context

My requirement is to set some dynamic variables in a for loop to the datapower context something like :

<dp:set-variable name="'var://context/txn-info/appErrorInd[$i+1]'"
                value="'yes'" />

The variable $i will keep on changing. The above code isn't working. Can somebody give me a solution?

Upvotes: 2

Views: 7093

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243479

Use:

<dp:set-variable name="'var:{//context/txn-info/appErrorInd[$i+1]}'"
                 value="'yes'" />

The above is a mechanical correction of the provided code. Most likely it contains another, more subtle error. To correct this error, too, use:

<dp:set-variable name="'var:{(//context/txn-info/appErrorInd)[$i+1]}'"
                 value="'yes'" />

Explanation:

  1. Use of AVT.

  2. The [] operator has a higher precedence than the // pseudo-operator. To override this one needs to use explicitly brackets.

Upvotes: 1

Related Questions