2

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?

1 Answers1

1

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.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
  • Sorry for pinching in for this question now. Did not understand the above. Cant we use . Why the 'var:' part, kept oustside the curly braces? – Suresh Dec 29 '11 at 16:32
  • @user1004770: The string `"var:"` is constant -- not dynamically calculated. It is meaningful to use AVT (the {} brackets) for specifying dynamically-calculated values. – Dimitre Novatchev Dec 29 '11 at 16:50