The problem you are facing has to do with he nature of XQuery Updates. It uses a pending update list and applies all updates at the end of the query. The order of the update operation is well defined and is therefore independent from the order you give in your update statement. See some more information at https://docs.basex.org/wiki/Updates#Pending_Update_List.
So in your case, insert
is applied before replace
, so you are actually replacing your just already inserted node and thus overwrite this change.
To resolve this, I would just replace the text values and replace the B
node. Therefore, both of your operations are independent from another and their order of execution can be changed without a problem.
let $b := <B> Constants :</B>
for $x in doc('doc1')//Doc/Para[P[@n="1"]/B/text()="Constants : T"]/P[@n="1"]
return
(
replace value of node $x/text() with concat("T", $x/text()),
replace node $x/B with $b
)