Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath 基于父节点属性选择节点的Web配置转换条件/匹配_Xpath_Web Config Transform - Fatal编程技术网

Xpath 基于父节点属性选择节点的Web配置转换条件/匹配

Xpath 基于父节点属性选择节点的Web配置转换条件/匹配,xpath,web-config-transform,Xpath,Web Config Transform,我有一个像这样的变换 <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <a> <b> <c> <d> <e name="UpdateLanguageProfile"> <f xdt:Transform="Replace" xd

我有一个像这样的变换

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <a>
    <b>
      <c>
        <d>
          <e name="UpdateLanguageProfile">
            <f xdt:Transform="Replace" xdt:Locator="Condition(/..@name='UpdateLanguageProfile')">
              stuff here
            </f>
          </e>
        </d>
      </c>
    </b>
  </a>
这是无效的


因此,问题是,为了基于父节点中的属性选择f节点,我可以在条件(即XPath方括号)中放入什么内容。

答案是xdt:Locator和xdt:Transform不需要位于同一节点上。在我所见过的每个例子中,它们恰好位于同一个节点上

您可以这样做:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <a>
    <b>
      <c>
        <d>
          <e name="UpdateLanguageProfile" xdt:Locator="Match(name)">
            <f xdt:Transform="Replace">
              stuff here
            </f>
          </e>
        </d>
      </c>
    </b>
  </a>

这里的东西

如果完全删除xdt:Locator,会发生什么情况?对我来说,只要父对象具有指定的name属性,转换就可以正常工作,就像您在这里看到的那样…太棒了!我总是在同一个节点上与他们一起工作,但这样可以解决我遇到的一些问题。谢谢!我试图插入,但它不断地添加到第一个父对象,而不是插入的当前父对象。这
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <a>
    <b>
      <c>
        <d>
          <e name="UpdateLanguageProfile" xdt:Locator="Match(name)">
            <f xdt:Transform="Replace">
              stuff here
            </f>
          </e>
        </d>
      </c>
    </b>
  </a>