Search code examples
xpathxdt-transform

xdt transform locator that matches subnode content


i have the following node in web.config:

<configuration>
...
<scheduling>
 <agent>
  <param desc="database">core</param>
 </agent>
 <agent>
  <param desc="database">master</param>
 </agent>
</scheduling>
...
</configuration>

i want to remove the whole <agent> node with the child param node with master content. more or less my xdt transform node looks like:

<configuration>
...
<scheduling>
  <agent
         xdt:Transform="Remove"
         xdt:Locator="XPath(./param[@desc='database']/??????)" />
</scheduling>
...
</configuration>

as you see, i have no idea how to match with the node content string. What do i need to add in here?

environment notes: windows 7 - visual studio 2010 SP1


Solution

  • Add an extra test for text() into the locator. To match the <param> node:

    xdt:Locator="XPath(./param[@desc='database' and text()='master'])">
    

    EDIT: To match the <agent> node you need to move param into the predicate that XPath is matching:

    xdt:Locator="Condition(param/@desc='database' and param/text()='master')">