Database Reference
In-Depth Information
Example 3-8. Search page that uses straight XQuery
xquery
version
"3.0"
;
declare
option
exist:serialize
"method=xhtml media-type=text/html"
;
declare
variable
$
page-title
:=
"Search results with XQuery"
;
declare
variable
$
searchphrase
:=
request:get-parameter
(
"searchphrase"
,
());
<html>
<head>
<meta
HTTP-EQUIV
=
"
Content-Type
"
content
=
"
text/html; charset=UTF-8
"
/>
<title>
{
$
page-title
}
</title>
</head>
<body>
<h1>
{
$
page-title
}
</h1>
<p>
Search phrase: "
{
$
searchphrase
}
"
</p>
<ul>
{
for
$
line
in
collection
(
"/db/apps/exist101/data"
)//
SPEECH
/
LINE
[
contains
(.,
$
searchphrase
)]
return
<li>
from:
{
string
(
root
(
$
line
)/
PLAY
/
TITLE
)}
<br/>
<i>
{
string
(
$
line
)}
</i>
</li>
}
</ul>
</body>
</html>
When you now enter
fantasy
as a search phrase and press Search!, the result shown in
Figure 3-7
should appear.
Figure 3-7. Results of searching the plays for “fantasy”
Search WWH ::
Custom Search