I have following script which actually will add Test="Value" attribute to all nodes in xml document:
declare @xml XML = '
<root>
<text><b>test2</b></text>
<text>test</text>
<text>test</text>
<text>test</text>
</root>
'
while @xml.exist('//*[not(@TEST)]') = 1
begin
set @xml.modify('
insert attribute TEST {"value"}
into (//*[not(@TEST)])[1]
')
end
select @xml
But how to exclude specific nodes from this query? I want to apply this attribute to all nodes but "a", "b"