title: How to add attribute to all particular children of a node
body: <p>I have the following node in which I want to add attribute to all <code>add</code> nodes.</p>
  
  <pre><code>&lt;test&gt;
    &lt;add&gt;x1&lt;/add&gt;
    &lt;c&gt;&lt;add&gt;x2&lt;/add&gt;&lt;/c&gt;
    &lt;b att1="x"&gt;x&lt;/b&gt;
  &lt;/test&gt;
  </code></pre>
  
  <p>I tried</p>
  
  <pre><code>functx:add-attributes($test, xs:QName('att1'), 1)
  </code></pre>
  
  <p>It can add the attribute to the <code>test</code> node. But</p>
  
  <p>When I tried</p>
  
  <pre><code>functx:add-attributes($test/add, xs:QName('att1'), 1)
  </code></pre>
  
  <p>It added the attribute to the first add node but returns only add node with added attribute. Then when I tried with <code>$test//add</code> it throws error.</p>
  
  <p>When I  tried  </p>
  
  <pre><code>for $add in $test//add 
     return functx:add-attributes($add, xs:QName('att1'), 1)
  </code></pre>
  
  <p>It returns two add nodes individually. Now, how to restructure the original node to add the attributes to only the specified nodes.</p>