开发者

XDT Config Transforms - ReplaceAll?

I've got 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 transformation on this such that I can change the value o开发者_如何学Pythonf ALL instances of the Property element with Name="foo" - but I cant seem to get it to work.

I've tried:

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

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


It seems like Transform:Replace only replaces the first matched element from the documentation on msdn: ...If more than one element is selected, only the first selected element is replaced. I solved this issue by 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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜