有没有办法设置变量或以其他方式记住父元素,以便其子项的可以与另一个元素的子元素的两个匹配?< / p>
示例: 我想检查 它选择第一个<root>
<mybonds>
<bond>
<type>sellable</type>
<amount>100</amount>
</bond>
<bond>
<type>revocable</type>
<amount>5</amount>
</bond>
</mybonds>
<auctions>
<bond>
<type>sellable</type>
<amount>1</amount>
</bond>
<bond>
<type>revocable</type>
<amount>100</amount>
</bond>
<bond>
<type>sellable</type>
<amount>100</amount>
</bond>
</auctions>
</root>
mybonds
bound
中是否存在auctions
bonds
元素:也就是说,每个bond
必须与{{1}完全匹配}和type
。但是如果我尝试使用这个XPath表达式amount
/root/mybonds/bond[type = /root/auctions/bond/type and amount = /root/auctions/bond/amount]
,因为它与 两个不同的拍卖债券 相匹配,它们分别具有匹配的bond
和type
没有匹配,因为没有单个绑定 amounts
和type
。
答案 0 :(得分:0)
无法单独在XPath中完成。
for $b in /root/mybonds/bond
return if(/root/auctions/bond[type = $b/type and amount = $b/amount])
then $b
else ()