我想列出那些拥有不同宗教并且是邻居的国家。 我写过类似的东西:
<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>
答案 0 :(得分: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]