FatAntelope icon indicating copy to clipboard operation
FatAntelope copied to clipboard

Use Insert instead of InsertBefore when the delta only exist in target

Open chucklu opened this issue 3 years ago • 1 comments

source file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<startup>
		<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
	</startup>
	<appSettings>
		<add key="test20180421" value="1" />
		<add key="test20180422" value="2" />
	</appSettings>
</configuration>

target file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
	  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
  </startup>
  <appSettings>
	  <add key="test20180421" value="1" />
	  <add key="test20180422" value="2" />
	  <add key="test20180423" value="3" />
	  <add key="test20180424" value="4" />
	</appSettings>
</configuration>

The generated patch file is

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add key="test20180424" value="4" xdt:Transform="Insert" />
    <add key="test20180423" value="3" xdt:Transform="InsertBefore(/configuration/appSettings/add[(@key='test20180424')])" />
  </appSettings>
</configuration>

The expected format should be, which is good for manually maintain

<?xml version="1.0" encoding="utf-8"?>
<!--For more information on using transformations see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
	<appSettings>
		<add key="test20180423" value="3" xdt:Transform="Insert" />
		<add key="test20180424" value="4" xdt:Transform="Insert" />
	</appSettings>
</configuration>

chucklu avatar Dec 07 '21 08:12 chucklu

The reason why I would like to use Insert instead of InsertBefore is, when I remove and add another section . I can not smoothly write the xdt manually with InsertBefore. However I can manually write transform file with Insert

<?xml version="1.0" encoding="utf-8"?>
<!--For more information on using transformations see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
	<appSettings>
		<add key="test20180423" value="3" xdt:Transform="Insert" />
		<add key="test20180425" value="5" xdt:Transform="Insert" />
	</appSettings>
</configuration>

chucklu avatar Dec 07 '21 08:12 chucklu