'Use variable in xml path in xml.modify

Edit: SQL Server 2016. I'm running several xml.modify statements that all use pretty much the same path. I originally put an example that didn't match my error.
I'm trying to substitute the 'a/b/' in the path with the value in the variable @a. Here's what I'm using:

declare @ab varchar(5) = 'a/b/'
declare @xml xml = '<root><a><b><c><d></d></c></b></a></root>'
-- works
--set @xml.modify('insert attribute MyAtt {"No"} into (/root/a/b/c/d)[1]')
-- error
set @xml.modify('insert attribute MyAtt {"Yes"} into (/root/{sql:variable("@ab")}c/d)[1]')
select @xml

but I get a different error

Msg 9341, Level 16, State 1, Line 7
XQuery [modify()]: Syntax error near '{', expected a step expression.

There is no mismatch in {(, etc. I tried removing the braces and/or the double quotes around the variable name. No luck. Is this even possible? And if so, what am I missing?

Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source