祝大家新年快乐!
我正在使用BaseX学习 XQuery,现在面临以下问题。
我正在解析作为分发部分的factbook.xml文件。
以下查询运行正常:
for $country in db:open('factbook')//country
where $country/@population < 1000000 and $country/@population > 500000
return <country name="{$country/name}" population="{$country/@population}">
{
for $city in $country/city
let $pop := number($city/population)
order by $pop descending
return <city population="{$city/population/text()}"> {$city/name/text()}
</city>
}
</country>
但是在尝试生成运行第二个查询的 html 时 - 如果我尝试将其放入"{$country/@population}"
标记中,<h2>Country population: </h2>
我会看到一条错误消息“属性必须跟随根元素”。
<html><head><title>Some Countries</title></head><body>
{
for $country in db:open('factbook')//country
let $pop_c := $country/@population
where $pop_c < 1000000 and $pop_c > 500000
return
<p>
<h1>Country: {$country/name/text()}</h1>
<h2>Country population: #error comes if I put it here!#</h2>
{
for $city in $country/city
let $pop := number($city/population)
order by $pop descending
return ( <h3>City: {$city/name/text()}</h3>,
<p>City population: {$city/population/text()}</p>
)
}
</p>
}
</body></html>
我的错误在哪里?谢谢!