xmlxquerywebharvest

xpst0003 xquery syntax error


I want to query a webpage through following x query code. please help me. And it gives me following errors: XPST0003: XQuery syntax error in #...//json//sentences//trans); let#: expected "return", found ";".

<?xml version="1.0" encoding="UTF-8"?>
<config charset="UTF-8">
<var-def name="scrappedContent">
<xquery>
<xq-param name="doc">
    <html-to-xml outputtype="browser-compact" prunetags="yes">
      <http url="${url}"/>
    </html-to-xml>
  </xq-param>

  <xq-expression><![CDATA[
     declare variable $doc as node() external;
     let $transl := data($doc//query//results//json//sentences//trans);
     let $translitl := data($doc//query//results//json//sentences//translit);      

     let $data  := data($doc//div[@id="defId"])
     return
        <myContent>
          <transl>{$transl}</transl>
          <translitl>{$translitl}</translitl>
          <data>{$data}</data>
        </myContent>
   ]]>
</xq-expression>
</xquery>
</var-def>   
</config>

Solution

  • Replace:

     let $transl := data($doc//query//results//json//sentences//trans);
     let $translitl := data($doc//query//results//json//sentences//translit);      
    

    With:

     let $transl := data($doc//query//results//json//sentences//trans)
     let $translitl := data($doc//query//results//json//sentences//translit) 
    

    (No semi-colon after let's)

    That should improve things..

    HTH!