简体   繁体   English

XQuery空结果-为什么?

[英]XQuery empty result - why?

I would like to list the pairs of countries that have differend religion and are neighbours. 我想列举出宗教信仰不同并且是邻国的两个国家。 I have wrote something like that: 我写过这样的话:

<result query='9'>
{
  let $check := ""
  for $x in doc("m.xml")/m/country
  let $check := concat($check, "{$x[@car_code]}", " ")
  let $r1 := $x/religions[@percentage>50]  
  for $y in doc("m.xml")/m/country[@car_code = $x/border[@country]]
  let $r2 := $y/religions[@percentage>50]
  return
    <border>
      {
        if (($r2 != $r1) and ($y[ not(@car_code = tokenize($check, "/s"))]))
        then
           (<a>
           <country name="{$x/name}" religion="{$r1}"/> 
           <country name="{$y/name}" religion="{$r2}"/>
           </a>)
        else()      
      }           
    </border>  
}  
</result>

but it returns only 但它只返回

<result query='9'/>

And I have no idea why. 而且我不知道为什么。 Thanks for any help 谢谢你的帮助

edit: Sory. 编辑:Sory。 Data: 数据:

<m>
   <country car_code="AL">
     <name>Albania</name>
     <religions percentage="70">Muslim</religions>
     <religions percentage="10">Roman Catholic</religions>
     <religions percentage="20">Albanian Orthodox</religions>
     <border country="GR" length="282"/>
     <border country="MK" length="151"/>
     <border country="YU" length="287"/>
   </country>
   <country car_code="GR">
     <name>Greece</name>
     <religions percentage="1.3">Muslim</religions>
     <religions percentage="98">Greek Orthodox</religions>
     <border country="AL" length="282"/>
     <border country="MK" length="228"/>
     <border country="BG" length="494"/>
     <border country="TR" length="206"/>
   </country>
.
.
.
</m>

In this line 在这条线

for $y in doc("m.xml")/m/country[@car_code = $x/border[@country]]

you're comparing the @car_code attribute with border elements that have a @country attribute . 你比较@car_code具有边界元素属性@country属性 Do not use a predicate but an axis step: 不要使用谓词,而要使用轴步:

for $y in doc("m.xml")/m/country[@car_code = $x/border/@country]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM