XPathは、XMLの2つのサブツリー間で外部キー検索を実行できますか?
質問
次の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>
... <!> quot; bucket <!> quot;を返すXPathはどうなりますか? <!> quot; red <!> quot;を含むおよび<!> quot; blue <!> quot;?
解決
XSLTを使用している場合、キーを設定することをお勧めします。
<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
他のヒント
これはうまくいくと思う:
/root/base/tent[/root/bucket/tent/@key = @key ]/@color
それはきれいではありません。他の検索と同様に、current()を使用する必要があります:
/ root / bucket [/ root / base / tent [@key = current()/ tent / @ key] / @ color = 'blue'または/ root / base / tent [@key = current()/ tent / @ key] / @ color = 'red']
JeniTには、適切な応答/コードがここにリストされています。 XMLドキュメントを調べる前にキーを作成し、そのキーに対して一致を実行する必要があります。
所属していません StackOverflow