Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xdt transforms by a child node attribute

I'm trying to create transform that will remove a node by it child node based on this answer without success

so that:

<?xml version="1.0"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http1" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

will be transformed to:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">        
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http1" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

this is what I've so far:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly xdt:Transform="Remove" xdt:Locator="XPath(./assemblyIdentity[@name='System.Net.Http'])">
        <assemblyIdentity name="System.Net.Http" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

you can use this online transform simulator

like image 289
Ofir Avatar asked Aug 21 '26 14:08

Ofir


1 Answers

The most important thing to note is that the element that you want to remove inherits default namespace xmlns="urn:schemas-microsoft-com:asm.v1". That said, your attempted XPath will not match anything since it didn't account for the namespace.

You can either ignore the namespace (inadvisable), or create a prefix that point to the default namespace and use that prefix in your XPath, for example:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:pref="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly xdt:Transform="Remove" xdt:Locator="XPath(./pref:assemblyIdentity[@name='System.Net.Http']/..)">
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

I prefer using Condition as suggested in the linked answer:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:pref="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly xdt:Transform="Remove" xdt:Locator="Condition(pref:assemblyIdentity/@name='System.Net.Http')">
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
like image 158
har07 Avatar answered Aug 24 '26 13:08

har07



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!