4

次の 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 は何でしょうか?

4

4 に答える 4

5

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
于 2008-09-27T21:19:35.683 に答える
2

私はこれがうまくいくと思います:

/root/base/tent[/root/bucket/tent/@key = @key ]/@color
于 2008-09-26T21:21:51.583 に答える
1

それはきれいではありません。他のルックアップと同様に、current() を使用する必要があります。

/root/bucket[/root/base/tent[@key = current()/tent/@key]/@color = 'blue' または /root/base/tent[@key = current()/tent/@key ]/@color = '赤']

于 2008-09-27T01:31:25.523 に答える
0

JeniTには、ここにリストされている適切な応答/コードがあります。XMLドキュメントをウォークする前にキーを作成してから、そのキーに対して照合を実行する必要があります。

于 2008-09-29T21:23:14.050 に答える