2013-02-05 8 views
5

Web設定に次のXMLがあります.Web.config変換を使用して削除する属性を選択したいが、削除する要素を選択したい子要素の1つの値に基づいて決定します。私は子要素<param desc="database">master</param>ではなく、成功しません基づいて、削除のための第二の薬剤の要素を選択しようとするために、次の試してみました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> 

私のweb.configファイルには、このようなものです。

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

答えて

6

xdt:Locator属性がCondition構文を使用する必要があるthis questionに答えたように、これはあなたの設定を削除します。したがって、必要なセレクターは:

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

' master'にマッチさせたい場合、このxpathはより正確になります: 'param [@ desc = 'database']/text()= 'master''。それ以外の場合は、マスター 'と一致する可能性があります。 –

-1

ただ、最後に/..を追加し、それはそれを行う必要があります。..

を例えば

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

...最後まで? –

+0

フロントに '//'が必要な場合がありますが、選択した 'param'要素を削除することができれば、'/.. 'はそれを行うべきです – Martin

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

+0

Sitecoreのパッチ適用機能は、私はweb.configの変換を使用して、環境に基づいて異なるweb.configファイルを作成したいと考えています。したがって、ある環境ではXMLノードが削除されますが、別の環境ではそのまま残されます。 –

関連する問題