<a>
{
for $p in doc("x.xml")/user//district
where data($p/@population) div data($p/@area) > 20
return <b>
<c> {$p/@name/string()} </c>
<d> {$p/@population div $p/@area} </d>
<d> {$p/@city/string()}</e>
</b>
}
</a>
我正在获得该地区的ID,但我想要这个国家的名字。所以我想从城市回到小区。就像下面的片段一样,我正在获取国家(id ='f0_149')但我无法匹配它并打印国家名称'Austria'instead。
我是Xquery的新手,所以我不知道很多事情。
XML FILE SNIPPET:
<?xml version="1.0" encoding="UTF-8"?>
<user xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<country id='f0_149' name='Austria' capital='f0_1467' population='10000000' total_area='50000' >
<name>
Austria
</name>
<district id='f0_17440' name='Burgenland' country='f0_149' capital='f0_2291' population='250000' area='5000'>
<city id='f0_2291' country='f0_149' province='f0_17440'>
<name>
Eisenstadt
</name>
<population year='87'>
10102
</population>
</city>
答案 0 :(得分:0)
您可以使用parent::
XPath轴:
<c> { $p/parent::country/@name/string() } </c>