title: Xquery to save data in a XML file
body: <p>Following is the XML structure -</p>
  
  <pre><code>&lt;Documents&gt;
   &lt;Doc n="Name1" year="2010"&gt;
   .....
   &lt;/Doc&gt;
   &lt;Doc n="Name2" year="2010"&gt;
   .....
   &lt;/Doc&gt;
   &lt;Doc n="Name3" year="2011"&gt;
   .....
   &lt;/Doc&gt;
   &lt;Doc n="Name4" year="2011"&gt;
   .....
   &lt;/Doc&gt;
  </code></pre>
  
  <p></p>
  
  <p>I am using BaseX to store this document. I need to extract
  some data from this and store it as a xml file. Say, I need a separate
  xml file for years.</p>
  
  <p>How to get this done ?</p>