Database Reference
In-Depth Information
Now what if you want to show the result as an HTML page instead? That's called
serialization , and Example 2-3 shows one of the ways to do it.
Example 2-3. Basic XQuery code returning HTML
xquery version "3.0" ;
declare option exist:serialize "method=html media-type=text/html" ;
let $ msg := 'Hello XQuery'
return
<html>
<head>
<title> Hello XQuery </title>
</head>
<body>
<h3> It is now { current-dateTime ()} and so { $ msg } ! </h3>
</body>
</html>
XQuery-initiated readers might have noticed that we did not declare the exist name‐
space prefix. eXist has most eXist-specific namespace prefixes predeclared for you, so
you don't have to explicitly mention them in your code.
Hello XSLT
XSLT is built into eXist using (by default) the Saxon XSLT processor. The examples
contain a simple stylesheet to show you how this works. The stylesheet in
Example 2-4 takes the XML from Example 2-1 and turns it into an HTML page.
Example 2-4. Transformation of the example XML into HTML
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" version= "1.0" >
<xsl:template match= "/" >
<html>
<head>
<title> Hello XSLT </title>
</head>
<body>
<h1> Item overview </h1>
<ul>
<xsl:for-each select= "//Item" >
<li>
<xsl:value-of select= "@name" /> :
<xsl:value-of select= "." />
</li>
</xsl:for-each>
</ul>
Search WWH ::




Custom Search