xslkey

Can XPath do a foreign key lookup across two subtrees of an XML?

梦想的初衷 提交于 2019-11-29 08:01:06
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> ...what would the XPath be that returns that the "bucket" contains "red" and "blue"? If you're using XSLT, I'd recommend setting up a key: <xsl:key name="tents" match="base/tent" use="@key" /> You can then get the <tent> within <base> with a particular key using key('tents', $id) Then you can do key('tents', /root/bucket/tent/@key)/@color or, if $bucket is a particular <bucket> element, key(

Can XPath do a foreign key lookup across two subtrees of an XML?

Deadly 提交于 2019-11-28 01:19:24
问题 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> ...what would the XPath be that returns that the "bucket" contains "red" and "blue"? 回答1: If you're using XSLT, I'd recommend setting up a key: <xsl:key name="tents" match="base/tent" use="@key" /> You can then get the <tent> within <base> with a particular key using key('tents', $id) Then you