XPath中的任意连接

时间:2015-11-05 22:23:09

标签: xml xpath

有没有办法设置变量或以其他方式记住父元素,以便其子项的可以与另一个元素的子元素的两个匹配?< / 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] ,因为它与 两个不同的拍卖债券 相匹配,它们分别具有匹配的bondtype没有匹配,因为没有单个绑定 amountstype

1 个答案:

答案 0 :(得分:0)

XPath 1.0

无法单独在XPath中完成。

XPath 2.0

for $b in /root/mybonds/bond 
    return if(/root/auctions/bond[type = $b/type and amount = $b/amount])
               then $b
               else ()