I am using the following XQuery code for selecting all .html documents within a collection of exist-db. The script should create an XML document (serialized as JSON) with document URI and title (which is stored as the first H1 element). However the the element remains empty. Why?
xquery version "3.0";
declare option exist:serialize "method=json media-type=text/javascript";
<result> {
let $data-collection := '/db/output'
for $doc in collection($data-collection)
where contains(base-uri($doc), '.html')
return
<item>
<url>{base-uri($doc)}</url>
<title>{$doc/h1/text()}</title>
</item>
}
</result>