如果我有这个简单的file.xml:
<?xml version="1.0" encoding="UTF-8"?>
<employees>
<employee>
<name>
Lorenzo Vinci
</name>
<address>
Via Rosa Luxemburg 68 A, Imola
<state>
Italia
</state>
</address>
</employee>
<employee>
<name>
Marco Di Nicola
</name>
<address>
Via Venezia, Pescara
<state>
Italia
</state>
</address>
</employee>
<employee>
<name>
Luca Pompei
</name>
<address>
Via qualcosa, Londra
<state>
England
</state>
</address>
</employee>
</employees>
我希望得到所有以州名开头的员工&#34;我&#34;。所以我写了这个问题:
let $emp := doc("employees.xml")
for $e in $emp//employee
let $state := $e/address/state
return starts-with($state, "I")
但函数start-with始终返回false。我也试过
return starts-with(string($state), "I")
但它是一样的。 我哪里错了? 感谢
答案 0 :(得分:3)
return starts-with(normalize-space(string($state)), "I")
应该这样做,在状态元素的开头有很多空格
答案 1 :(得分:1)
或者,当xml结构如下时,您的查询将起作用 -
<employees>
<employee>
<name>Lorenzo Vinci</name>
<address>Via Rosa Luxemburg 68 A, Imola
<state>Italia</state>
</address>
</employee>
......
......
</employees>