Database Reference
In-Depth Information
If you feel bold enough, you could also try this: do not remove the processing instruc‐
tion (or use one of the other files) and copy the shakes.xsl file from /db/apps/demo/
data to /db/apps/exist101/data , like we did with the plays. When you now open the
document in your browser (with the URL given before), you'll see a nicely rendered
HTML page.
Listing the Plays (XML)
Let's write our first XQuery script and have it find out which plays we have in
the /db/apps/exist101/data collection. For now we'll return the result as an XML frag‐
ment, and in the next section we'll create a nice-looking HTML page from this. There
is more than one way to do this (where have I heard that line before?), and we'll show
you a few.
First, perform the following preparations:
1. Browse to the dashboard ( http://localhost:8080/exist/ ).
2. If you're not already logged in, log in as admin (click on “Not logged in” in the
upper-left corner).
3. Click on the “eXide - XQuery IDE” tile. eXide will open in a new browser win‐
dow or tab.
4. Click on New XQuery. A new tab opens with an empty XQuery script.
5. Click Save and save the script as /db/apps/exist101/playlist.xq .
Listing with the collection Function
In our first version of the solution, we will use the XPath collection function to iter‐
ate over all the resources in our data collection. Enter the following code and press
Run:
for $ resource in collection ( "/db/apps/exist101/data" )
return
base-uri ( $ resource )
The collection function returns a sequence of documents ( document-node items)
for all the resources found in the given collection and its subcollections (for details,
see “The collection Function” on page 93 ). The XPath base-uri function returns the
URI for a document-node , which in eXist is the path leading to the resource.
Running this should return (in the bottom window) a list with the plays, including
each one's full path in the database.
Turning this list of strings into a well-formed XML fragment is simple:
Search WWH ::




Custom Search