Your inner query returns new constructed elements, which can’t be updated. To perfrom a successfull update the inner query should return elements retrieved from the database. You can achieve this by rewriting the query in the following way:
update
for $outer in (
for $inner in input()/doc
where $inner/system=‘X’
and $inner/disclosure_level = ‘Public’
return $inner
)[position() < 100]
let $target := $outer/disclosure_level
do
replace $target …
The inner query now returns the bindings of $inner instead of the element .