Hi,
I have a long XML document like this :
<cities> <city> <name>Paris</name> <zip>75000</zip> <alt_names> <name>paris</name> </alt_names> </city> <city> <name>Cesson-Sévigné</name> <zip>35510</zip> <alt_names> <name>paris</name> </alt_names> </city> </cities>
My XQuery is supposed to return the cities whose name begin with a few letters contained in "$cityname". So I use this :
let $search := request:get-parameter("search","")
return <cities> { for $city in collection("cities")//city[starts-with(alt_names/name,$search)] return <city> {$city/name} {$city/zip} </city> } </cities>
But there is a problem with the [starts-with(alt_names/name,$search)] part. It seems that I cannot use the same tag name ("name") both in "city" and in "alt_names". The error is :
[XPTY0004] No sequence (element name { ... }, element name { ... }) allowed.
1) Is this a bug?
2) What is the equivalent in BaseX to request:get-parameter, which works in "eXist db" and affects the GET parameter (here "search") to the $search variable?
Thank you for your help,
Regards, Grégoire
Hi,
I have a long XML document like this :
<cities> <city> <name>Paris</name> <zip>75000</zip> <alt_names> <name>paris</name> </alt_names> </city> <city> <name>Cesson-Sévigné</name> <zip>35510</zip> <alt_names> <name>cesson-sevigne</name> </alt_names> </city> </cities>
My XQuery is supposed to return the cities whose name begin with a few letters contained in "$search". So I use this :
let $search := request:get-parameter("search","")
return <cities> { for $city in collection("cities")//city[starts-with(alt_names/name,$search)] return <city> {$city/name} {$city/zip} </city> } </cities>
But there is a problem with the [starts-with(alt_names/name,$search)] part. It seems that I cannot use the same tag name ("name") both in "city" and in "alt_names". The error is :
[XPTY0004] No sequence (element name { ... }, element name { ... }) allowed.
1) Is this a bug?
2) What is the equivalent in BaseX to request:get-parameter, which works in "eXist db" and affects the GET parameter (here "search") to the $search variable?
Thank you for your help,
Regards, Grégoire
PS : I corrected the variable name which is, obviously "$search" and not "$cityname" (please ignore the previous message).
Dear Grégoire,
collection("cities")//city[starts-with(alt_names/name,$search)] [...]
[XPTY0004] No sequence (element name { ... }, element name { ... }) allowed.
- Is this a bug?
The first argument of starts-with() accepts only single items. The following version will work as expected:
collection("cities")//city[altnames/name[starts-with(., $search)]]
- What is the equivalent in BaseX to request:get-parameter, which works in
"eXist db" and affects the GET parameter (here "search") to the $search variable?
BaseX doesn't support HTTP requests on it. We're currently working on an extension of our integrated libraries, so we plan, e.g., to include the EXPath proposal for HTTP requests in near future.
Hope this helps, Christian
basex-talk@mailman.uni-konstanz.de