XDT Config Transforms - ReplaceAll?

I have a custom section in my web.config file similar to this structure:

<Messages> <Message id="1'> <Property Name="foo" value="bar" /> </Message> <Message id="2'> <Property Name="foo" value="bar2" /> </Message> </Messages> 

I want to apply a custom conversion to it to change the value of ALL instances of the Property element using Name = "foo" - but I can't get it to work.

I tried:

 <Messages> <Message> <Property Name="foo" value="updated" xdt:Locator=Match(Name) xdt:Transform="Replace" /> </Message> </Mesasges> 

I can remove all elements by replacing Transform = Replace with Transform = RemoveAll - any ideas how I can achieve something similar to replace all values?

+6
source share
1 answer

Transform: Replace seems to replace only the first matched item from the msdn documentation : ... If multiple items are selected, only the first selected item is replaced. I solved this problem using a combination of Match-Conditions and SetAttributes, something like:

 <Messages> <Message> <Property value="updated" xdt:Locator=Condition(@Name='foo') xdt:Transform="SetAttributes(value)" /> </Message> </Messages> 
+7
source

Source: https://habr.com/ru/post/898179/


All Articles