Reputation: 949
I want that the function XQuery to return the id_fermata from the instance of file tratta.xml where id_linea of the file tratta.xml matches with id of the linea.xml
The file linea.xml is :
<root_linea >
<linea id="ID_180">
<nome>180</nome>
<tipologia>circolare</tipologia>
<e_ricorsiva>true</e_ricorsiva>
<orario_prima_partenza>09:20:00</orario_prima_partenza>
<cadenza_mattina>20</cadenza_mattina>
<cadenza_pomeriggio>20</cadenza_pomeriggio>
<cadenza_sera>20</cadenza_sera>
<cadenza_notte>20</cadenza_notte>
<id_tratta>ID_1</id_tratta>
<id_corsa_effettiva>ID_1</id_corsa_effettiva>
<id_corsa_effettiva>ID_2</id_corsa_effettiva>
</linea>
</root_linea>
the file tratta.xml is:
<root_tratta>
<tratta id="ID_1">
<id_fermata> ID_1 </id_fermata>
<id_linea>ID_180</id_linea>
<tratta_successiva>ID_2</tratta_successiva>
</tratta>
</root_tratta>
the function XQuery is :
declare function local:retrivalInfo() as element()* {
let $id := request:get-parameter("id", '')
let $linee := doc("linea.xml")/root_linea/linea
for $lin in $linee
where $lin/nome = $id
return(
let $tratte := doc("tratta.xml")/root_tratta/tratta
for $tra in $tratte
where $tra/id_linea=$lin/@id
return(
<tr>
<td><font color="white">{data($tra/id_fermata)}</font></td>
</tr>
)
)
};
The problem of this function is that don't view nothing. How can resolve this problem?
Upvotes: 0
Views: 475
Reputation: 16927
Works fine for me. The output for id = 180 is <tr>
<td><font color="white"> ID_1 </font></td>
</tr>
Perhaps you have not set the correct id-parameter on the get request? Or it does not find the files on the server? Or some schema in the files that makes the id non comparable (if something like that exists)?
Also you can simplify the function quite a lot, if you replace where with []. Then you do not even need to use two returns:
declare function local:retrivalInfo() as element()* {
let $id := request:get-parameter("id", '')
for $lin in doc("linea.xml")/root_linea/linea[nome = $id]
let $tra := doc("tratta.xml")/root_tratta/tratta[id_linea=$lin/@id]
return(
<tr>
<td><font color="white">{data($tra/id_fermata)}</font></td>
</tr>
)
};
(With the correct schemas you might even be able to use the element-with-id functions)
Upvotes: 1