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

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

My web.config looks 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 tried the following to try and select the second agent item to delete based on the child <param desc="database">master</param>, but without 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>
+5
source share
3 answers

As indicated in this question, an attribute xdt:Locatorshould use syntax Condition. Therefore, the required selector:

<agent type="Sitecore.Tasks.DatabaseAgent"
       xdt:Transform="Remove"
       xdt:Locator="Condition(param/@desc='database' and param/text()='master')" />
+6
source

Sitecores . :

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

:

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

+2

Just add /..to the end, this should do it.

eg.

XPath(configuration/sitecore/scheduling/agent/param[text()='master']/..)
-1
source

All Articles