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>
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')" />
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With