title: How to create Payload Dynamically in wso2 ESB
body: <p>I am invoking a wso2 DSS service which returns me data like:</p>
  
  <pre><code>&lt;IdentifierCollection xmlns="http://tempuri.org/"&gt;
   &lt;Identifier&gt;
          &lt;One&gt;1&lt;/One&gt;
      &lt;Two&gt;2&lt;/Two&gt;
      &lt;Three&gt;3&lt;/Three&gt;
      &lt;/Identifier&gt;
  &lt;/IdentifierCollection&gt;
  </code></pre>
  
  <p>To invoke Dss my esb code is:</p>
  
  <pre><code>&lt;payloadFactory&gt;
              &lt;format&gt;
                 &lt;p:GetIdentifier xmlns:p="http://tempuri.org/"&gt;
                    &lt;xs:ID xmlns:xs="http://tempuri.org/"&gt;$1&lt;/xs:ID&gt;
                 &lt;/p:GetIdentifier &gt;
              &lt;/format&gt;
              &lt;args&gt;
                 &lt;arg expression="get-property('ID')"/&gt;
              &lt;/args&gt;
           &lt;/payloadFactory&gt;
           &lt;send receive="ResponseOfGetIdentifier"&gt;
              &lt;endpoint key="IdentifierEP"/&gt;
           &lt;/send&gt;
  </code></pre>
  
  <p>Now in my ResponseOfGetIdentifier Sequence i am capturing all data in properties</p>
  
  <pre><code>&lt;sequence xmlns="http://ws.apache.org/ns/synapse" name="ResponseOfGetIdentifier"&gt;
     &lt;iterate xmlns:ns="http://org.apache.synapse/xsd" xmlns:p="http://tempuri.org/" preservePayload="true" attachPath="//p:EntriesCollection" expression="//p:EntriesCollection/p:Entries" id="IterateForResponse"&gt;
        &lt;target&gt;
  &lt;sequence&gt;
  &lt;property xmlns:ns="http://org.apache.synapse/xsd" xmlns:p="http://tempuri.org" name="ResponseOne" expression="//p:Identifier/p:one" scope="default" type="STRING"/&gt;
  &lt;property xmlns:ns="http://org.apache.synapse/xsd" xmlns:p="http://tempuri.org" name="ResponseTwo" expression="//p:Identifier/p:Two" scope="default" type="STRING"/&gt;
  &lt;property xmlns:ns="http://org.apache.synapse/xsd" xmlns:p="http://tempuri.org" name="ResponseThree" expression="//p:Identifier/p:Three" scope="default" type="STRING"/&gt;
  &lt;payloadFactory&gt;
           &lt;format&gt;
  &lt;tns:ProductIdentifier xmlns:tns="http://globalArther.products.com"&gt;
  &lt;IdentifierProducts&gt;
  &lt;Product1&gt;$1&lt;/Product1&gt;
  &lt;Product2&gt;$2&lt;/Product&gt;
  &lt;Product3&gt;$3&lt;/Product3&gt;
  &lt;/IdentifierProducts&gt;
  &lt;/tns:ProductIdentifier&gt;
  &lt;/format&gt;
  &lt;args&gt;
  &lt;arg expression="get-property('ResponseOne')"/&gt;
  &lt;arg expression="get-property(''ResponseTwo)"/&gt;
  &lt;arg expression="get-property('ResponseThree')"/&gt;
  &lt;/args&gt;
  &lt;/payloadFactory&gt;
  &lt;/sequence&gt;
  &lt;/target&gt;
     &lt;/iterate&gt;
  &lt;/sequence&gt;
  </code></pre>
  
  <p>Since my dss response contains only one iteration of Identifier node hence above code is working but when my identifier node count is more than one i.e</p>
  
  <pre><code>&lt;IdentifierCollection xmlns="http://tempuri.org/"&gt;
   &lt;Identifier&gt;
          &lt;One&gt;1&lt;/One&gt;
      &lt;Two&gt;2&lt;/Two&gt;
      &lt;Three&gt;3&lt;/Three&gt;
      &lt;/Identifier&gt;
  &lt;Identifier&gt;
          &lt;One&gt;a&lt;/One&gt;
      &lt;Two&gt;b&lt;/Two&gt;
      &lt;Three&gt;c&lt;/Three&gt;
      &lt;/Identifier&gt;
  &lt;/IdentifierCollection&gt;
  </code></pre>
  
  <p>, since my payload can take only one data it takes the second iteration data and shows me only single result as:</p>
  
  <pre><code>&lt;tns:ProductIdentifier xmlns:tns="http://globalArther.products.com"&gt;
      &lt;IdentifierProducts&gt;
      &lt;Product1&gt;a&lt;/Product1&gt;
      &lt;Product2&gt;b&lt;/Product&gt;
      &lt;Product3&gt;c&lt;/Product3&gt;
      &lt;/IdentifierProducts&gt;
      &lt;/tns:ProductIdentifier&gt;
  </code></pre>
  
  <p>But i want my response as :</p>
  
  <pre><code>&lt;tns:ProductIdentifier xmlns:tns="http://globalArther.products.com"&gt;
          &lt;IdentifierProducts&gt;
          &lt;Product1&gt;1&lt;/Product1&gt;
          &lt;Product2&gt;2&lt;/Product&gt;
          &lt;Product3&gt;3&lt;/Product3&gt;
          &lt;/IdentifierProducts&gt;
  &lt;IdentifierProducts&gt;
          &lt;Product1&gt;a&lt;/Product1&gt;
          &lt;Product2&gt;b&lt;/Product&gt;
          &lt;Product3&gt;c&lt;/Product3&gt;
          &lt;/IdentifierProducts&gt;
  &lt;/tns:ProductIdentifier&gt;
  </code></pre>
  
  <p>So now my question is how can i do that i.e how can i make my payload dynamic i.e. i want to add every iteration in my payload.
  Looking forward to your answers.Thanks in advance</p>