title: Mule ESB Dataweave consume two XML streams, create one XML output
body: <p><a href="https://i.stack.imgur.com/jOaYb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jOaYb.png" alt="enter image description here"></a></p>
  
  <p>I have two XML streams from Bigcommerce API. One XML stream contains the order information, the other stream contains the line items (products). I am attempting to combine the two XML streams with dataweave and get one xml document as the output. When I run the flow as attached I do not get all products, but only one set of products (the first set)</p>
  
  <p>==================================================================</p>
  
  <p>Here is the order.xml stream:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;order&gt;
  &lt;id&gt;40144&lt;/id&gt;
  &lt;date&gt;2016-05-01&lt;/date&gt;
  &lt;/order&gt;
  </code></pre>
  
  <p>Here is the products stream (notice we will have multiple products here):</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;products&gt;
  &lt;product&gt;
  &lt;id&gt;1234&lt;/id&gt;
  &lt;order_id&gt;40144&lt;/order_id&gt;
  &lt;product_id&gt;12345&lt;/product_id&gt;
  &lt;order_address_id&gt;12&lt;/order_address_id&gt;
  &lt;name&gt;Widget&lt;/name&gt;
  &lt;/product&gt;
  &lt;product&gt;
  &lt;id&gt;53245&lt;/id&gt;
  &lt;order_id&gt;40144&lt;/order_id&gt;
  &lt;product_id&gt;56435&lt;/product_id&gt;
  &lt;order_address_id&gt;12&lt;/order_address_id&gt;
  &lt;name&gt;Super Widget&lt;/name&gt;
  &lt;/product&gt;
  &lt;/products&gt;
  </code></pre>
  
  <p>Here is the Mule flow config (system variables changed)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
  xmlns:imaps="http://www.mulesoft.org/schema/mule/imaps"
  xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" 
  xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" 
  xmlns:http="http://www.mulesoft.org/schema/mule/http" 
  xmlns:imap="http://www.mulesoft.org/schema/mule/imap" 
  xmlns="http://www.mulesoft.org/schema/mule/core" 
  xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
  xmlns:spring="http://www.springframework.org/schema/beans" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.mulesoft.org/schema/mule/xml 
  http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
  http://www.mulesoft.org/schema/mule/imaps 
  http://www.mulesoft.org/schema/mule/imaps/current/mule-imaps.xsd
  http://www.springframework.org/schema/beans 
  http://www.springframework.org/schema/beans/spring-beans-current.xsd
  http://www.mulesoft.org/schema/mule/core 
  http://www.mulesoft.org/schema/mule/core/current/mule.xsd
  http://www.mulesoft.org/schema/mule/http 
  http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
  http://www.mulesoft.org/schema/mule/imap 
  http://www.mulesoft.org/schema/mule/imap/current/mule-imap.xsd
  http://www.mulesoft.org/schema/mule/objectstore 
  http://www.mulesoft.org/schema/mule/objectstore/current/mule-objectstore.xsd
  http://www.mulesoft.org/schema/mule/ee/dw 
  http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd"&gt;
  &lt;imaps:connector name="IMAP" backupFolder="backup" validateConnections="true" backupEnabled="true" checkFrequency="900" doc:name="IMAP"/&gt;
  &lt;http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="myserver.net" port="443" doc:name="HTTP Request Configuration"&gt;
      &lt;http:basic-authentication username="user" password="password"/&gt;
  &lt;/http:request-config&gt;
  &lt;flow name="scattgathFlow"&gt;
      &lt;imaps:inbound-endpoint host="192.168.1.1" port="993" responseTimeout="10000" user="user" password="password" doc:name="IMAP" connector-ref="IMAP"/&gt; 
      &lt;set-variable doc:name="Variable" value="#[message.inboundProperties.subject.replaceAll('[^0-9\\-]', '')]" variableName="email_subj"/&gt;
      &lt;http:request config-ref="HTTP_Request_Configuration" path="/api/v2/orders/#[email_subj]" method="GET" doc:name="HTTP" metadata:id="72233863-af08-4d0d-9a75-5b726b6d117e"&gt;
      &lt;/http:request&gt; 
      &lt;!--  Sub flow to retrieve products --&gt;  
      &lt;flow-ref name="payload1" doc:name="payload1" metadata:id="896da22a-11f4-4a80-9b38-85507261b002"/&gt;
          &lt;dw:transform-message metadata:id="8c4bb84a-74f8-4761-8f56-859dcf50473c" doc:name="Transform Message"&gt;
              &lt;dw:input-payload doc:sample="products.xml"/&gt;
              &lt;dw:input-outbound-property propertyName="MULE_ENCODING"/&gt;
              &lt;dw:set-payload&gt;
      &lt;![CDATA[%dw 1.0
      %output application/xml
      %input payload application/xml
      ---
      {
      newxml: {
           billto: payload.order.customer_id as :string,
           shipping: payload.order.status,
      products: {
          productID: payload.products.product.product_id,
          sku: payload.products.product.sku,
          name: payload.products.product.name
      }
  }
  }]]&gt;&lt;/dw:set-payload&gt;
  &lt;/dw:transform-message&gt;
  &lt;logger message="#[message.payload]" level="INFO" doc:name="Logger"/&gt;
  &lt;/flow&gt;
  &lt;sub-flow name="payload1" &gt;
      &lt;http:request config-ref="HTTP_Request_Configuration" path="/api/v2/orders/#[email_subj]/products.xml" method="GET" doc:name="HTTP" metadata:id="4806e0ff-68f0-4295-baff-d65b07ae5190"/&gt;
  &lt;/sub-flow&gt;
  &lt;/mule&gt;
  </code></pre>