CameronWills/FatAntelope

Incorrect condition?

myasoex opened this issue · 5 comments

Hi there

Check it out
Source web.config

<configuration>  
  <appSettings>
    <add key="MyService.Api" value="0" />
  </appSettings>  
</configuration>

Target web.config

<configuration>  
  <appSettings>
    <add key="MyService.Api" value="1" />
    <add key="MyService.Api" value="2" />    
  </appSettings>  
</configuration>

Transformation

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add xdt:Locator="Condition([(@value='1')])" value="1" xdt:Transform="SetAttributes(value)" />
    <add key="MyService.Api" value="2" xdt:Transform="Insert" />
  </appSettings>
</configuration>

What gives us the next result

<configuration>  
  <appSettings>
    <add key="MyService.Api" value="0" />
  <add key="MyService.Api" value="2" /></appSettings>  
</configuration>

Should not the condition to be xdt:Locator="Condition([(@value='0')])"?

I'm experiencing the same issue

<configuration>  
  <appSettings>
    <add key="KeyA" value="ValueA" />
  </appSettings>  
</configuration>

Target web.config

<configuration>  
  <appSettings>
    <add key="KeyB" value="ValueB" />
    <add key="KeyC" value="ValueC" />    
  </appSettings>  
</configuration>

Transformation

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add xdt:Locator="Condition([(@key='KeyB')])" value="ValueB" xdt:Transform="Replace(value)" />
    <add key="KeyC" value="ValueC" xdt:Transform="Insert" />
  </appSettings>
</configuration>

Again i believe the condition should be xdt:Locator="Condition([(@value='KeyA')])"? It seens like an issue when the transform should remove a lonely leaf node and add new..

I gave up using this library, currently I am using the linq to xml to migrate the configuration file.

Hi All,

I've put up a fix now. Apologies for the delay in addressing this - dad life got in the way and then it fell off the radar. It's a tricky one, the xdt:Locator needs to be valid for the current state of the transformed document. And you can omit the xdt:Locator altogether if there is only one node with that name. So after this fix the working patch for @myasoex example looks like:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add value="1" xdt:Transform="SetAttributes(value)" />
    <add key="MyService.Api" value="2" xdt:Transform="Insert" />
  </appSettings>
</configuration>

And similarly for your example @Hans-MartinHannibalLauridsen , the working generated patch doesn't include an xdt:Locator:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add key="KeyB" value="ValueB" xdt:Transform="Replace" />
    <add key="KeyC" value="ValueC" xdt:Transform="Insert" />
  </appSettings>
</configuration>

I'll package up and push into nuget shortly.

Cheers,
Cameron

Thanks, much obliged😀

Closing as I think that change has addressed the issue?