<div dir="ltr"><br>Greetings,<br><div><br><div class="" itemprop="text">

<p>Running in Basex I get the following error:</p>

<p><a href="https://www.w3.org/TR/xquery-update-10/#ERRXUST0001" rel="nofollow">XUST0001</a> element constructor: no updating expression allowed.</p>

<p>When trying to insert <strong>insert nodes test as first into $c</strong> </p>

<p>I feel like my code is following the <a href="http://www.xmlmind.com/tutorials/XQueryUpdate/" rel="nofollow">examples</a> I see online although clearly I've got something wrong. </p>

<p>How do I insert a node with a <code>for</code> loop?</p>

<pre><code>declare namespace db="<a href="http://basex.org/modules/db">http://basex.org/modules/db</a>";
declare namespace file="<a href="http://expath.org/ns/file">http://expath.org/ns/file</a>";
declare variable $form13FFileNumber as xs:string external;

let $data := db:open('13F')//data[contains(edgarSubmission/formData/coverPage/form13FFileNumber,$form13FFileNumber)]

let $fields := 

<form13FFile>
{
for $c in $data return 
insert nodes <b4>test</b4> as first into $c  
}
</form13FFile>

return file:write(concat('../OUT/' , $form13FFileNumber , '.xml'), $fields)
</code></pre>

<p>To be more clear my xml looks something like</p>

<pre><code>   <data>
     <first_Child>text</first_child>
   </data>
   <data>
     <first_Child>text</first_child>
   </data>
</code></pre>

<p>and I would like it to adjust to</p>

<pre><code><form13FFile>
    <data>
     <b4>test</b4>
     <first_Child>text</first_child>
    </data>
    <data>
     <b4>test</b4>
     <first_Child>text</first_child>
    </data>
</form13FFile>
</code></pre>
    </div><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><br>Regards<br>Alex<br></div><div><a href="http://tech.jahtoe.com" target="_blank">tech.jahtoe.com</a><br></div><div><a href="http://bafila.jahtoe.com" target="_blank">bafila.jahtoe.com</a><br></div></div></div></div>
</div></div>