Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case insensitive match locator config transformation

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

like image 366
Chakri Avatar asked Jun 07 '19 12:06

Chakri


1 Answers

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.

like image 176
Orace Avatar answered Sep 30 '22 06:09

Orace