0

我想列出具有不同宗教和邻国的国家对。我写过类似的东西:

<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>

但它只返回

<result query='9'/>

我不知道为什么。谢谢你的帮助

编辑:对不起。数据:

<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>
4

1 回答 1

1

在这一行

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

您正在将属性与具有属性@car_code的边框元素进行比较。不要使用谓词而是使用轴步:@country

for $y in doc("m.xml")/m/country[@car_code = $x/border/@country]
于 2013-06-10T11:56:48.090 回答