title: Xquery extract tags' opening declaration
body: <p>I have following XML:</p>
  
  <pre><code>&lt;RULES&gt;
      &lt;TRAP name="trap1" oid=".1.2.3"&gt;
        &lt;VAR_LIST&gt;
          &lt;VAR name="var1" value=".1.2.3.1"/&gt;
          &lt;VAR name="var2" value=".1.2.3.2"/&gt;
        &lt;/VAR_LIST&gt;
      &lt;/TRAP&gt;
      &lt;TRAP name="trap2" oid=".1.2.4"&gt;
          ...
      &lt;/TRAP&gt;
      ...
  &lt;/RULES&gt;
  </code></pre>
  
  <p>I would like to generate flattened summary so I iterate through it as follows:</p>
  
  <pre><code>for $trap in /RULES/TRAP
      for $var in $rule/VAR_LIST/VAR
         return (opening-tag-declaration($trap), opening-tag-declaration($var), "&amp;#10;")
  </code></pre>
  
  <p>I would like to get following output, but I don't know how to extract tag's opening declaration only...</p>
  
  <pre><code>&lt;TRAP name="trap1" oid=".1.2.3&gt; &lt;VAR name="var1" value=".1.2.3.1"/&gt;
  &lt;TRAP name="trap1" oid=".1.2.3&gt; &lt;VAR name="var2" value=".1.2.3.2"/&gt;
  &lt;TRAP name="trap2" oid=".1.2.4&gt; ...
  ...
  </code></pre>