Copying data between a list and a repeating element

This task shows how to copy data from a list into a repeating element by using ESQL.

About this task

Consider the form of the following XML input message:
     <inner>abcde fghij 12345</inner>
where the element inner is of type xsd:list, and therefore has three associated string values, rather than a single value.
To copy the three values into an output message, where each value is associated with an instance of repeating elements as shown here:
you might expect that the following ESQL syntax works:
   SET D = CARDINALITY(InputBody.str1.*[]);
   WHILE M <= D DO
      SET OutputRoot.MRM.str1[M] = InputBody.inner.*[M];
      SET M = M + 1;
However, the statement:
	SET OutputRoot.MRM.str1[M] = InputBody.inner.*[M];
requests a tree copy from input to output. Because the output element does not yet exist, the statement creates it, and its value and type are set from the input.
Therefore, to create the output message with the required format, given an input element which is of type xsd:list, use the FIELDVALUE function to explicitly retrieve only the value of the input element:
	SET OutputRoot.MRM.str1[M] = FIELDVALUE(InputBody.inner.*[M]);