[xquery-talk] XQuery in Web Application

Wei, Alice J. ajwei at indiana.edu
Fri Mar 7 15:16:02 PST 2008

Hi, XQueryers,

  I don't know if anyone has tried this.
  I intend on turning the code below into a web interface so I could search through my database collections. I used Saxon to debug my errors, and it apparently is giving me something like this in the following:

  F [Saxon9B XQuery] Cannot find a matching 1-argument function named {http://chausie.slis.indiana.edu:8080/exist/xquery/request}get-parameter()

 It appears that this is an XQuery issue, but I am not sure if something like get-parameter() or  session:set-attribute() is an XQuery supported function.
 If anyone has tried designing a web search using XQuery, I would love to hear about what are the possible solutions to my errors here.

Thanks in advance.

xquery version "1.0";
(: Searching through Collections :)

declare namespace request="http://chausie.slis.indiana.edu:8080/exist/xquery/request";
declare namespace session="http://chausie.slis.indiana.edu:8080/exist/xquery/session";
declare variable $data := fn:collection("xmldb:exist://db/cbml")//ad;

declare function local:input($search as xs:anyAtomicType)
as xs:string?
    let $search := request:get-parameter($search")
       ( session:set-attribute("search", 0)

declare function local:search($search as xs:anyAtomicType
    ) as element()
let $sorted_result:=
for $doc in session:get-attribute(distinct-values($search))
order by $doc
return $doc
for $d at $count in $sorted_result
    return (
        session:set-attribute("search", $count),
        if ($count lt 1) then
            <p>Sorry, there are no results retrieved back. Please check for your input. </p>
        else if ($count gt 200) then
            <p>Sorry, too many results returned. Please refine your search to have them displayed.</p>
       let $journal := $search[. =$d][1]/ancestor::cbml//seriesStmt/title[@level='journal']
let $volume := $search[. =$d][1]/ancestor::cbml//seriesStmt/idno[@type='volume']
let $issue := $search[. =$d][1]/ancestor::cbml//seriesStmt/idno[@type='issue']
let $head2 := $search[.=$d][1]/parent::ad/child::head
let $para := $search[.=$d][1]/parent::ad/child::p
let $note := $search[.=$d][1]/parent::ad/child::note
let $pb := $search[.=$d][1]/preceding::pb[1]
order by $d
Showing Result: {$count} / {count($sorted_result)}
<publication>Volume {data($volume)}, Issue {data($issue)}</publication>
<information>Source from page {$pb}</information></ad>

declare function local:main() as node()?
    let  $search := xs:string(request:get-parameter("search", ()))
                if ($search) then local:guess($search)
                                <p>You have not entered any search terms!</p>

    <head><title>Collection Advertisement Testing Page</title></head>
        <form action="{session:encode-url(request:get-uri())}">
            <table border="0">
                    <th colspan="2">Welcome to My XQuery Web Application Testing</th>
                    <td>Type in Your Search Term:</td>
                    <td><input type="text" name="search" size="3"/></td>
                    <td colspan="2" align="left"><input type="submit"/></td>
        { local:main() }
        <p><small>View <a href="guess.xql?_source=yes">source code</a></small></p>

Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
ajwei at indiana.edu

More information about the talk mailing list