XPath가 XML의 두 하위 트리에서 외국 키 조회를 할 수 있습니까?
문제
다음 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를 사용하는 경우 키를 설정하는 것이 좋습니다.
<xsl:key name="tents" match="base/tent" use="@key" />
그런 다음 얻을 수 있습니다 <tent>
이내에 <base>
특정 key
사용
key('tents', $id)
그런 다음 할 수 있습니다
key('tents', /root/bucket/tent/@key)/@color
또는 if $bucket
특별합니다 <bucket>
요소,
key('tents', $bucket/tent/@key)/@color
다른 팁
I think this will work:
/root/base/tent[/root/bucket/tent/@key = @key ]/@color
It's not pretty. As with any lookup, you need to use current():
/root/bucket[/root/base/tent[@key = current()/tent/@key]/@color = 'blue' or /root/base/tent[@key = current()/tent/@key]/@color = 'red']
JeniT has the appropriate response / code listed here. You need to create the key before you walk the XML Document, then perform matches against that key.
제휴하지 않습니다 StackOverflow