变换在Web.config中基于子节点值选择节点(Select node based on chil

2019-08-16 18:49发布

我有下面的XML在我的web配置,我想选择使用的web.config变换去除的属性,但我想选择基于子元素之一的值去除的元素。

我的web.config是这样的:

<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>

我曾尝试以下尝试选择基于子元件上用于删除的第二药剂元件<param desc="database">master</param>但没有成功。

<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>

Answer 1:

正如在回答这个问题的xdt:Locator属性需要使用Condition语法。 所以需要选择是:

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


Answer 2:

只需使用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



Answer 3:

只需添加/..到最后,应该这样做..

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


文章来源: Select node based on child node value in Web.config Transform