Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect condition? #9

Closed
myasoex opened this issue Aug 6, 2019 · 5 comments
Closed

Incorrect condition? #9

myasoex opened this issue Aug 6, 2019 · 5 comments

Comments

@myasoex
Copy link

myasoex commented Aug 6, 2019

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')])"?

@Hans-MartinHannibalLauridsen
Copy link

Hans-MartinHannibalLauridsen commented Nov 28, 2019

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..

@chucklu
Copy link

chucklu commented Nov 28, 2019

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

CameronWills added a commit that referenced this issue Nov 29, 2019
When writing the XDT patch, we were incorrectly using the new tree's values for the xdt:Locator. This was done previously for the scenario when calculating the locator XPath for child nodes after applying changes to the parent node that affected the parent's unique trait / XPath, as locators in the patch need to be valid in current state of transformed document, and Microsoft's XDT library applies the transforms in depth-first order.
@CameronWills
Copy link
Owner

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

@Hans-MartinHannibalLauridsen

Thanks, much obliged😀

@CameronWills
Copy link
Owner

Closing as I think that change has addressed the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants