title: Merge nodes in XML (Oracle)
body: <p>I wrote this query:</p>
  
  <pre><code>WITH Cities 
  AS(
      SELECT DISTINCT EXTRACTVALUE(Address,'(//City)[1]') AS City
      FROM Reader
  )
  SELECT XMLAGG(XMLELEMENT("Cities", 
  XMLATTRIBUTES(c.City AS "Title"),
  XMLELEMENT("Readers",
  XMLELEMENT("Reader",XMLATTRIBUTES(r.FirstName,r.SecondName)))))
  FROM Reader r,Cities c
  WHERE EXTRACTVALUE(r.Address,'(//City)[1]') = c.City;
  </code></pre>
  
  <p>It generates the document:</p>
  
  <pre><code>&lt;Cities Title="New York"&gt;
      &lt;Readers&gt;
          &lt;Reader FIRSTNAME="JON" SECONDNAME="SHOW"&gt;&lt;/Reader&gt;
      &lt;/Readers&gt;
  &lt;/Cities&gt;
  &lt;Cities Title="New York"&gt;
      &lt;Readers&gt;
          &lt;Reader FIRSTNAME="Poll" SECONDNAME="Aeron"&gt;&lt;/Reader&gt;
      &lt;/Readers&gt;
  &lt;/Cities&gt;
  &lt;Cities Title="Kharkiv"&gt;
      &lt;Readers&gt;
          &lt;Reader FIRSTNAME="Slavik" SECONDNAME="Romanov"&gt;&lt;/Reader&gt;
      &lt;/Readers&gt;
  &lt;/Cities&gt;
  &lt;Cities Title="Boca Juniors"&gt;
      &lt;Readers&gt;
          &lt;Reader FIRSTNAME="Julio " SECONDNAME="Pedro"&gt;&lt;/Reader&gt;
      &lt;/Readers&gt;
  &lt;/Cities&gt;
  &lt;Cities Title="London"&gt;
      &lt;Readers&gt;
          &lt;Reader FIRSTNAME="Johnny " SECONDNAME="Smith"&gt;&lt;/Reader&gt;
      &lt;/Readers&gt;
  &lt;/Cities&gt;
  </code></pre>
  
  <p>I would like to combine nodos with the same attributes ("New York"), exactly, the result was so:</p>
  
  <pre><code>&lt;Cities&gt;
  &lt;!-- --&gt;
    &lt;City Title="New York"&gt;
      &lt;Readers&gt;
        &lt;Reader FirstName="JON" SecondName="SHOW" /&gt;
        &lt;Reader FirstName="Poll" SecondName="Aeron" /&gt;
      &lt;/Readers&gt;
    &lt;/City&gt;
  &lt;/Cities&gt;
  </code></pre>
  
  <p>Data for this sql query: <a href="http://sqlfiddle.com/#!4/2d231" rel="nofollow">http://sqlfiddle.com/#!4/2d231</a></p>