0

I want to query a site and generate HTML. I am new to XQuery. I am using eXide from eXist-db. I tried to use oXygen but keep having troubles with the eXist-db. Besides that I don't understand why this code does not work in eXide:

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>

It gives me an error in line 34 saying it was expected </table> and found *,

enter image description here

Joe Wicentowski
  • 5,159
  • 16
  • 26
props
  • 105
  • 1
  • 7

1 Answers1

1

There is a typo at the end of the following line, namely a missing comma between the variable and the string in $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)

Everything else seems to be syntactically correct.

If eXide does not support the syntax $array?* for getting all entries of an array, you can try rewriting it from

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

to

let $rows := $x?table?rows
for $i in 1 to array:size($rows)
let $data := $rows($i)
[...]
Leo Wörteler
  • 4,191
  • 13
  • 10
  • yeah, if i delete the for() line, it works, it has anything to do with that? – props Jun 07 '17 at 13:45
  • If `?*` is the problem, you can try the rewrite I edited into my answer. – Leo Wörteler Jun 07 '17 at 14:57
  • it worked, but now its giving me another error: "err:XQST0033 error found while loading module http: prefix 'http' bind to 'http://expath.org/ns/http-client' ", Hope you can help me – props Jun 07 '17 at 15:03
  • Error code `XQST0033`: "The prolog contains more than one declaration for the same namespace prefix, which is not allowed." Do you bind the prefix `http` to both `"http://exist-db.org/xquery/httpclient"` and `"http://expath.org/ns/http-client"`? Only the second one should be needed. – Leo Wörteler Jun 07 '17 at 20:05