本文介绍了XPath 可以跨 XML 的两个子树进行外键查找吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有以下 XML...
Say I have the following 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>
...返回bucket"包含red"和blue"的 XPath 是什么?
...what would the XPath be that returns that the "bucket" contains "red" and "blue"?
推荐答案
如果您使用 XSLT,我建议您设置一个密钥:
If you're using XSLT, I'd recommend setting up a key:
<xsl:key name="tents" match="base/tent" use="@key" />
然后您可以使用
key('tents', $id)
然后你就可以了
key('tents', /root/bucket/tent/@key)/@color
或者,如果 $bucket
是一个特定的 元素,
or, if $bucket
is a particular <bucket>
element,
key('tents', $bucket/tent/@key)/@color
这篇关于XPath 可以跨 XML 的两个子树进行外键查找吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!