title: XMLType Concat multiple instances of the same xml tag
body: <p>My starting point is this issue : <a href="https://stackoverflow.com/questions/29821779/insert-xmltype-into-xmltype-in-specified-place-pl-sql">Insert xmltype into xmltype in specified place [PL/SQL]</a></p>
  
  <p>Now, I have this simple example:</p>
  
  <pre><code>DECLARE
    l_head_xml     XMLTYPE
    := xmltype.CREATEXML(
       '&lt;ord&gt;
          &lt;head&gt;
            &lt;ord_code&gt;123&lt;/ord_code&gt;
            &lt;ord_date&gt;01-01-2015&lt;/ord_date&gt;
          &lt;/head&gt;
        &lt;/ord&gt;');
  
    l_pos_xml      XMLTYPE
    := xmltype.CREATEXML(
       '&lt;pos&gt;
          &lt;pos_code&gt;456&lt;/pos_code&gt;
          &lt;pos_desc&gt;description&lt;/pos_desc&gt;
        &lt;/pos&gt;');
  
    l_complete_xml XMLTYPE;
  BEGIN
  
    FOR i IN 1 .. 2
    LOOP
      SELECT XMLELEMENT("MAIN_TAG",
                        XMLAGG(XMLCONCAT(l_head_xml, l_pos_xml)))
      INTO l_complete_xml
      FROM dual;
    END LOOP;
  
    dbms_output.put_line(l_complete_xml.getstringval());
  END;
  </code></pre>
  
  <p>In my case, I have a loop who gets multiple instances of these two tags: <code>l_head_xml</code> and <code>l_pos_xml</code>. The final result my be something like this:</p>
  
  <pre><code>  &lt;MAIN_TAG&gt;
      &lt;Item&gt;
          &lt;ord&gt;
              &lt;head&gt;
                  &lt;ord_code&gt;123&lt;/ord_code&gt;
                  &lt;ord_date&gt;01-01-2015&lt;/ord_date&gt;
              &lt;/head&gt;
          &lt;/ord&gt;
          &lt;pos&gt;
              &lt;pos_code&gt;456&lt;/pos_code&gt;
              &lt;pos_desc&gt;description&lt;/pos_desc&gt;
          &lt;/pos&gt;
      &lt;/Item&gt;
      &lt;Item&gt;
          &lt;ord&gt;
              &lt;head&gt;
                  &lt;ord_code&gt;123&lt;/ord_code&gt;
                  &lt;ord_date&gt;01-01-2015&lt;/ord_date&gt;
              &lt;/head&gt;
          &lt;/ord&gt;
          &lt;pos&gt;
              &lt;pos_code&gt;456&lt;/pos_code&gt;
              &lt;pos_desc&gt;description&lt;/pos_desc&gt;
          &lt;/pos&gt;
      &lt;/Item&gt;
  &lt;/MAIN_TAG&gt;
  </code></pre>
  
  <p>How can I do this, using XMLType funtions (not deprecated - I'm using Oracle 11g) and without using temporary variables to concatenate each of the XML block on each instance.</p>