title: XQuery | How to transform all attributes into elements
body: <p>I need to prepare a single XQuery file, which for any input XML file will transform all attributes into elements. I have it done in XSLT down below. <code>tranformation.xsl</code>: </p>
  
  <pre><code>&lt;xsl:template match="*" name="xsl:initial-template"&gt;
      &lt;xsl:element name="{name()}"&gt;
          &lt;xsl:for-each select="@*"&gt;
              &lt;xsl:element name="{name()}"&gt;
                  &lt;xsl:value-of select="."/&gt;
              &lt;/xsl:element&gt;
          &lt;/xsl:for-each&gt;
  
          &lt;xsl:apply-templates select="child::node()"/&gt;
  
      &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;
  </code></pre>