Database Reference
In-Depth Information
First, let's set up a basic HTML (or more precisely, XHTML) page without much con‐
tent to see how this works. Enter the code in
Example 3-4
and save it as
plays-home.xq
.
Example 3-4. Basic HTML page code
xquery
version
"3.0"
;
<html>
<head>
<meta
HTTP-EQUIV
=
"
Content-Type
"
content
=
"
text/html; charset=UTF-8
"
/>
<title>
Our Shakespeare plays
</title>
</head>
<body>
<h1>
Our Shakespeare plays
</h1>
</body>
</html>
Now run it. In the bottom part of the eXide screen, you'll see the same unexciting
piece of XHTML as you entered. Running it from the browser (
http://localhost:8080/
exist/rest/db/apps/exist101/plays-home.xq
) doesn't make it look any better. So what's
missing?
What's missing here is that you have to tell eXist that this is XHTML and that it
should
serialize
it as such. There is more than one way to do this (see
“Serialization”
on page 118
), but the easiest is to add an
exist:serialize
option in the XQuery prolog
to tell eXist to serialize the query result as XHTML and send it to the browser as an
HTML page and not as a bare piece of XML:
declare
option
exist:serialize
"method=xhtml media-type=text/html"
;
While we're changing things anyway, let's also get rid of the double entry for the
page's title and put this in a global variable.
Example 3-5
shows our improved basic
HTML page.
Example 3-5. Improved version of the basic HTML page code
xquery
version
"3.0"
;
declare
option
exist:serialize
"method=xhtml media-type=text/html"
;
declare
variable
$
page-title
:=
"Our Shakespeare plays"
;
<html>
<head>
<meta
HTTP-EQUIV
=
"
Content-Type
"
content
=
"
text/html; charset=UTF-8
"
/>
<title>
{
$
page-title
}
</title>
</head>
<body>
<h1>
{
$
page-title
}
</h1>
Search WWH ::
Custom Search