假设我有以下 XML...
<root>
<base>
<tent key="1" color="red"/>
<tent key="2" color="yellow"/>
<tent key="3" color="blue"/>
</base>
<bucket>
<tent key="1"/>
<tent key="3"/>
</bucket>
</root>
...返回“桶”包含“红色”和“蓝色”的 XPath 是什么?
最佳答案
如果您使用的是 XSLT,我建议您设置一个 key :
<xsl:key name="tents" match="base/tent" use="@key" />
然后您可以获得 <tent>
在 <base>
内与特定 key
使用
key('tents', $id)
然后你可以做
key('tents', /root/bucket/tent/@key)/@color
或者,如果$bucket
是一个特别的<bucket>
元素,
key('tents', $bucket/tent/@key)/@color
关于xml - XPath 可以跨 XML 的两个子树执行外键查找吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/142010/