gpt4 book ai didi

xpath - Web配置转换条件/匹配以基于父节点属性选择节点

转载 作者:行者123 更新时间:2023-12-03 15:24:46 24 4
gpt4 key购买 nike

我有一个看起来像这样的变换

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

因此,仅当父节点具有具有指定值的属性时,我才希望xdt:Locator选择f节点。

xdt:Locator被转换为以下xpath表达式:
/a/b/c/d/e/f[/..@name='UpdateLanguageProfile']

哪个无效。

所以问题是,为了根据父节点中的属性选择f节点,我可以在Condition中添加什么,即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>

关于xpath - Web配置转换条件/匹配以基于父节点属性选择节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13886291/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com