2017-06-07 51 views
0

我想查詢一個網站並生成html,我是xquery的新手。 我使用exdb存在,我試圖使用氧氣,但一直存在的數據庫的麻煩。 除此之外我不明白爲什麼這個代碼不EXIDEXquery錯誤Xpst0003語法錯誤

xquery version "3.0"; 
import module namespace http = "http://exist-db.org/xquery/httpclient"; 
import module namespace util = "http://exist-db.org/xquery/util"; 

declare option exist:serialize "method=xhtml media-type=text/html"; 

let $spreadsheet-url := 'https://docs.google.com/spreadsheets/d/1rNHWMonN4RSnvxMYpkqeGHG_bBz-WpxCI-2_Wc/gviz/ tq?tqx=out:json' 



let $spreadsheet-response := http:get(xs:anyURI($spreadsheet-url), true(), <Headers/>) 

let $body := util:base64-decode($spreadsheet-response/httpclient:body/text()) 

let $x := parse-json(substring-before(substring-after($body,'('),');')) 

let $odk-server:="http//192.168.0.104" 

let $amp:="&amp;" 

let $gmap-api-key:="AIzaSyCYC9h9pMGGvREo................" 

return 
    <html> 
     <head> 
      <title>Results</title> 
     </head> 
     <body> 
      <table> 
       <tr> 
        <th>Mapa</th> 
        <th>Detalhes</th> 
       </tr> 
       { 
        for $data in $x?table?rows?* 
         let $latitude := $data?c(11)?v 
         let $longitude := $data?c(12)?v 
         let $map-url := concat("https://maps.googleapis.com/api/staticmap?center=",$latitude,",", $longitude, $amp, "zoom=18", $amp, "size=400x400", $amp, "markers=color:blue|", $latitude,",",$longitude, $amp,"key=",$gmap-api-key) 

         let $name:= $data?c(8)?v 
         let $age:=$data=?c(9)?v 
         let $date:=$data?c(10)?f 
         let $image:= replace($data?c(15)?v,"http://aggregate.defaultdomain", $odk-server) 
         return 
          <tr> 
           <td><img src='{$map-url}' alt="map"/></td> 
           <td> 
            <img src='{$image}' height="200" width="200" alt="imagem"/> 
           <p>{$name}</p><p>{$age}</p><p>{$date}</p> 
           </td> 
           <td> 
           </td> 
          </tr> 

       } 

      </table> 

     </body> 
    </html> 

工作,它給了我34行說,預計「」發現「*」的錯誤,

enter image description here

+0

是否有你在這裏展示的部分之前更多的代碼? XQuery腳本不能以'return'開頭。 –

+0

@LeoWörteler是的,但它只有它的diretores和地圖APIs代碼 – props

+0

哪個版本的eXist? – joewiz

回答

1

在下一行末尾有一個拼寫錯誤,即在$amp"key="中變量和字符串之間缺少逗號。

let $map-url := concat("https://maps.googleapis.com/api/staticmap?center=",$latitude,",", 
     $longitude, $amp, "zoom=18", $amp, "size=400x400", $amp, "markers=color:blue|", 
     $latitude,",",$longitude, $amp"key=",$gmap-api-key) 

其他的一切在句法上似乎都是正確的。

如果EXIDE不支持語法$array?*爲得到一個數組的所有條目,你可以嘗試從

for $data in $x?table?rows?* 
[...] 

重寫它

let $rows := $x?table?rows 
for $i in 1 to array:size($rows) 
let $data := $rows($i) 
[...] 
+0

謝謝,我編輯,但錯誤仍然存​​在 – props

+0

看起來像一個bug,BaseX接受語法。 –

+0

是的,如果我刪除for()行,它的工作原理,它有什麼關係? – props