title: How to Generate an XML File from a set of XPath Expressions?
body: <p>I want to be able to generate a complete XML file, given a set of XPath mappings.</p>
  
  <p>The input could specified in two mappings: (1) One which lists the XPath expressions and values; and (2) the other which defines the appropriate namespaces.</p>
  
  <pre><code>/create/article[1]/id                 =&gt; 1
  /create/article[1]/description        =&gt; bar
  /create/article[1]/name[1]            =&gt; foo
  /create/article[1]/price[1]/amount    =&gt; 00.00
  /create/article[1]/price[1]/currency  =&gt; USD
  /create/article[2]/id                 =&gt; 2
  /create/article[2]/description        =&gt; some name
  /create/article[2]/name[1]            =&gt; some description
  /create/article[2]/price[1]/amount    =&gt; 00.01
  /create/article[2]/price[1]/currency  =&gt; USD
  </code></pre>
  
  <p>For namespaces:</p>
  
  <pre><code>/create               =&gt; xmlns:ns1='http://predic8.com/wsdl/material/ArticleService/1/
  /create/article       =&gt; xmlns:ns1='http://predic8.com/material/1/‘
  /create/article/price =&gt; xmlns:ns1='http://predic8.com/common/1/‘
  /create/article/id    =&gt; xmlns:ns1='http://predic8.com/material/1/'
  </code></pre>
  
  <p>Note also, that it is important that I also deal with XPath <strong>Attributes</strong> expressions as well. For example: I should also be able to handle attributes, such as:</p>
  
  <pre><code>/create/article/@type =&gt; richtext
  </code></pre>
  
  <p>The final output should then look something like:</p>
  
  <pre><code>&lt;ns1:create xmlns:ns1='http://predic8.com/wsdl/material/ArticleService/1/'&gt;
      &lt;ns1:article xmlns:ns1='http://predic8.com/material/1/‘ type='richtext'&gt;
          &lt;name&gt;foo&lt;/name&gt;
          &lt;description&gt;bar&lt;/description&gt;
          &lt;ns1:price xmlns:ns1='http://predic8.com/common/1/'&gt;
              &lt;amount&gt;00.00&lt;/amount&gt;
              &lt;currency&gt;USD&lt;/currency&gt;
          &lt;/ns1:price&gt;
          &lt;ns1:id xmlns:ns1='http://predic8.com/material/1/'&gt;1&lt;/ns1:id&gt;
      &lt;/ns1:article&gt;
      &lt;ns1:article xmlns:ns1='http://predic8.com/material/2/‘ type='richtext'&gt;
          &lt;name&gt;some name&lt;/name&gt;
          &lt;description&gt;some description&lt;/description&gt;
          &lt;ns1:price xmlns:ns1='http://predic8.com/common/2/'&gt;
              &lt;amount&gt;00.01&lt;/amount&gt;
              &lt;currency&gt;USD&lt;/currency&gt;
          &lt;/ns1:price&gt;
          &lt;ns1:id xmlns:ns1='http://predic8.com/material/2/'&gt;2&lt;/ns1:id&gt;
      &lt;/ns1:article&gt;
  &lt;/ns1:create&gt;
  </code></pre>
  
  <p>PS: This is a more detailed question to a previous <a href="https://stackoverflow.com/questions/11385323">question</a> asked, although due to a series of further requirements and clarifications, I was recommended to ask a more broader  question in order to address my needs.</p>
  
  <p>Note also, I am implementing this in Java. So either a Java-based or XSLT-based solution would both be perfectly acceptable. thnx.</p>
  
  <p>Further note: I am really looking for a <strong>generic</strong> solution. The XML shown above is just an example.</p>