Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select node based on child node value in Web.config Transform

I have the following XML in my web config and I would like to select an attribute for removal using web.config transforms, but I would like to select the element for removal based on the value of one of the child elements.

My web.config is something like this:

<configuration>
   <sitecore>
       <scheduling>
          <agent type="Sitecore.Tasks.DatabaseAgent">
             <param desc="database">core</param>
          </agent>
          <agent type="Sitecore.Tasks.DatabaseAgent">
             <param desc="database">master</param>
          </agent>
       </scheduling>
    </sitecore>
 </configuration>

I have tried the following to try to select the second agent element for deletion based on the child element <param desc="database">master</param> but with no success.

<configuration>
   <sitecore>
       <scheduling>
          <!-- Attempt 1 -->
          <agent type="Sitecore.Tasks.DatabaseAgent"
                 xdt:Transform="Remove"
                 xdt:Locator="XPath(configuration/sitecore/scheduling/agent/param[text()='master'])"/>

          <!-- Attempt 2 -->
          <agent type="Sitecore.Tasks.DatabaseAgent"
                 xdt:Transform="Remove">
             <param desc="database"
                    xdt:Locator="XPath([text()='master'])"/>
          </agent>
       </scheduling>
    </sitecore>
 </configuration>
like image 328
Matthew Dresser Avatar asked Feb 05 '13 23:02

Matthew Dresser


2 Answers

As answered in this question the xdt:Locator attribute needs to use the Condition syntax. So the required selector is:

<agent type="Sitecore.Tasks.DatabaseAgent"
       xdt:Transform="Remove"
       xdt:Locator="Condition(param/@desc='database' and param/text()='master')" />
like image 50
Matthew Dresser Avatar answered Oct 14 '22 04:10

Matthew Dresser


Just use Sitecores own config patcher. This will remove your setting:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <scheduling>
       <agent patch:instead="*[@type='Sitecore.Tasks.DatabaseAgent' and param='master']">
       </agent>
    </scheduling>
 </sitecore>
</configuration>

For more information, look here:

http://intothecore.cassidy.dk/2009/05/working-with-webconfig-include-files-in.html http://www.thescrewballdivision.com/playing-with-sitecore-include-files

like image 21
Sandbeck Avatar answered Oct 14 '22 05:10

Sandbeck