I am transforming values of appsettings in web.config file depending on the environment. I ran into an issue when there are keys with same name but with different cases, example as below
Local Value
<add xdt:Transform="RemoveAll" xdt:Locator="Match(key)" key="LOGINURL" value="xyf" />
Dev Value
<add xdt:Transform="RemoveAll" xdt:Locator="Match(key)" key="LoginUrl" value="abcd" />
I would like to replace the value of keys case insensitively.
TIA
You can use XPath with the Condition locator instead of Match.
And using the hack described here on building case insensitive matching in XPath you may be able to write this:
<add xdt:Transform="RemoveAll" xdt:Locator= "Condition(translate(@key,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='loginurl')"/>
The key and value attribute are useless since the elements are removed.
To edit elements use SetAttributes to keep the keys untouched.
<add xdt:Transform="SetAttributes" xdt:Locator="Condition(translate(@key,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='loginurl')" value="test.com" />
I tested all of it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With