简体   繁体   English

函数XQuery中的嵌套返回

[英]Nested return in function XQuery

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 我希望函数XQuery从文件tratta.xml的实例返回id_fermata,其中文件tratta.xml的id_linea与linea.xml的ID匹配

The file linea.xml is : 文件linea.xml是:

<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: 文件tratta.xml是:

          <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 : XQuery函数是:

         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? 如何解决这个问题?

Works fine for me. 对我来说很好。 The output for id = 180 is <tr> <td><font color="white"> ID_1 </font></td> </tr> id = 180的输出是<tr> <td><font color="white"> ID_1 </font></td> </tr>

Perhaps you have not set the correct id-parameter on the get request? 也许您没有在get请求上设置正确的id参数? 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)? 还是文件中的某些模式使ID不具有可比性(如果存在类似的东西)?

Also you can simplify the function quite a lot, if you replace where with []. 如果用[]代替where,也可以大大简化函数。 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) (使用正确的架构,您甚至可以使用element-with-id函数)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM