title: How to rename node element names using a FLWOR XQuery?
body: <p>How can I rename all <code>foo</code> tags as <code>baz</code> using an <code>XQuery</code> as below?</p>
  
  <p>FLWOR:</p>
  
  <pre><code>declare namespace map = "http://www.w3.org/2005/xpath-functions/map";
  declare namespace array = "http://www.w3.org/2005/xpath-functions/array";
  
  declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
  
  for $x in /root
  
  return rename node $x/root/foo as "baz"
  </code></pre>
  
  <p>Sample doc:    </p>
  
  <pre><code>  &lt;root&gt;
      &lt;foo&gt;bar&lt;/foo&gt;
    &lt;/root&gt;
  </code></pre>
  
  <p>output I'm looking for:</p>
  
  <pre><code>  &lt;root&gt;
      &lt;baz&gt;bar&lt;/baz&gt;
    &lt;/root&gt;
  </code></pre>
  
  <p>see also:</p>
  
  <p><a href="http://xqueryfiddle.liberty-development.net/nc4P6y8" rel="nofollow noreferrer">http://xqueryfiddle.liberty-development.net/nc4P6y8</a></p>
  
  <p>and:</p>
  
  <p><a href="https://stackoverflow.com/q/12009311/4531180">removing an element from xml using saxon xquery</a></p>
  
  <p>which uses something not entirely dissimilar..</p>