Reputation: 5427
if I have this simple 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>
I'd like to get all the employees whose state name begins with "I". So I've written the query:
let $emp := doc("employees.xml")
for $e in $emp//employee
let $state := $e/address/state
return starts-with($state, "I")
but the function starts-with always returns false. I've also tried with
return starts-with(string($state), "I")
but it's the same. Where am I wrong? Thanks
Upvotes: 0
Views: 99
Reputation: 2852
OR your query will work when the xml structure is like this -
<employees>
<employee>
<name>Lorenzo Vinci</name>
<address>Via Rosa Luxemburg 68 A, Imola
<state>Italia</state>
</address>
</employee>
......
......
</employees>
Upvotes: 1
Reputation: 504
return starts-with(normalize-space(string($state)), "I")
Should do the trick, there's a lot of whitespace at the start of the state element
Upvotes: 3