You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1539 lines
49 KiB
1539 lines
49 KiB
<?xml version="1.0" encoding="utf-8"?>
|
|
<!--XSLT Processor: SAXON 8.8 from Saxonica SAXON 8.8-->
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html lang="EN" xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN">
|
|
<head>
|
|
<meta name="generator" content=
|
|
"HTML Tidy for Windows (vers 14 February 2006), see www.w3.org" />
|
|
<title>XQuery Scripting Extension 1.0 Use Cases</title>
|
|
|
|
<style type="text/css">
|
|
/*<![CDATA[*/
|
|
code { font-family: monospace; }
|
|
|
|
div.constraint,
|
|
div.issue,
|
|
div.note,
|
|
div.notice { margin-left: 2em; }
|
|
|
|
div.issue
|
|
p.title { margin-left: -2em; }
|
|
|
|
ol.enumar { list-style-type: decimal; }
|
|
ol.enumla { list-style-type: lower-alpha; }
|
|
ol.enumlr { list-style-type: lower-roman; }
|
|
ol.enumua { list-style-type: upper-alpha; }
|
|
ol.enumur { list-style-type: upper-roman; }
|
|
|
|
li p { margin-top: 0.3em;
|
|
margin-bottom: 0.3em; }
|
|
|
|
sup small { font-style: italic;
|
|
color: #8F8F8F;
|
|
}
|
|
|
|
div.exampleInner pre { margin-left: 1em;
|
|
margin-top: 0em; margin-bottom: 0em}
|
|
div.exampleOuter {border: 4px double gray;
|
|
margin: 0em; padding: 0em}
|
|
div.exampleInner { background-color: #d5dee3;
|
|
border-top-width: 4px;
|
|
border-top-style: double;
|
|
border-top-color: #d3d3d3;
|
|
border-bottom-width: 4px;
|
|
border-bottom-style: double;
|
|
border-bottom-color: #d3d3d3;
|
|
padding: 4px; margin: 0em }
|
|
div.exampleWrapper { margin: 4px }
|
|
div.exampleHeader { font-weight: bold;
|
|
margin: 4px}
|
|
|
|
div.issue { border-bottom-color: black;
|
|
border-bottom-style: solid;
|
|
border-bottom-width: 1pt;
|
|
margin-bottom: 20pt;
|
|
}
|
|
|
|
th.issue-toc-head { border-bottom-color: black;
|
|
border-bottom-style: solid;
|
|
border-bottom-width: 1pt;
|
|
}
|
|
|
|
/*]]>*/
|
|
</style>
|
|
<link rel="stylesheet" type="text/css" href=
|
|
"http://www.w3.org/StyleSheets/TR/W3C-WD.css" />
|
|
</head>
|
|
<body>
|
|
<div class="head">
|
|
<p><a href="http://www.w3.org/"><img src=
|
|
"http://www.w3.org/Icons/w3c_home" alt="W3C" height="48" width=
|
|
"72" /></a></p>
|
|
<h1><a name="title" id="title"></a>XQuery Scripting Extension 1.0
|
|
Use Cases</h1>
|
|
<h2><a name="w3c-doctype" id="w3c-doctype"></a>W3C Working Draft 3
|
|
December 2008</h2>
|
|
<dl>
|
|
<dt>This version:</dt>
|
|
<dd><a href=
|
|
"http://www.w3.org/TR/2008/WD-xquery-sx-10-use-cases-20081203/">http://www.w3.org/TR/2008/WD-xquery-sx-10-use-cases-20081203/</a></dd>
|
|
<dt>Latest version:</dt>
|
|
<dd><a href=
|
|
"http://www.w3.org/TR/xquery-sx-10-use-cases/">http://www.w3.org/TR/xquery-sx-10-use-cases/</a></dd>
|
|
<dt>Previous version:</dt>
|
|
<dd><a href=
|
|
"http://www.w3.org/TR/2008/WD-xquery-sx-10-use-cases-20080328/">http://www.w3.org/TR/2008/WD-xquery-sx-10-use-cases-20080328/</a></dd>
|
|
<dt>Editor:</dt>
|
|
<dd><span><a href="http://snelson.org.uk/john">John
|
|
Snelson</a></span>, Oracle Corporation <a href=
|
|
"mailto:john.snelson@oracle.com"><john.snelson@oracle.com></a></dd>
|
|
</dl>
|
|
<p class="copyright"><a href=
|
|
"http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 2008 <a href="http://www.w3.org/"><acronym title="World Wide Web Consortium">W3C</acronym></a><sup>®</sup>
|
|
(<a href="http://www.csail.mit.edu/"><acronym title=
|
|
"Massachusetts Institute of Technology">MIT</acronym></a>, <a href=
|
|
"http://www.ercim.org/"><acronym title=
|
|
"European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>,
|
|
<a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved.
|
|
W3C <a href=
|
|
"http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
|
|
<a href=
|
|
"http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
|
|
and <a href=
|
|
"http://www.w3.org/Consortium/Legal/copyright-documents">document
|
|
use</a> rules apply.</p>
|
|
</div>
|
|
<hr />
|
|
<div>
|
|
<h2><a name="abstract" id="abstract"></a>Abstract</h2>
|
|
<p>This document specifies usage scenarios for the XQuery Scripting
|
|
Extension.</p>
|
|
</div>
|
|
<div>
|
|
<h2><a name="status" id="status"></a>Status of this Document</h2>
|
|
<p><em>This section describes the status of this document at the
|
|
time of its publication. Other documents may supersede this
|
|
document. A list of current W3C publications and the latest
|
|
revision of this technical report can be found in the <a href=
|
|
"http://www.w3.org/TR/">W3C technical reports index</a> at
|
|
http://www.w3.org/TR/.</em></p>
|
|
<p>This is a <a href=
|
|
"http://www.w3.org/2005/10/Process-20051014/tr.html#maturity-levels">
|
|
Working Draft</a> as described in the <a href=
|
|
"http://www.w3.org/2004/02/Process-20040205/tr.html">Process
|
|
Document</a>. It has been developed by the W3C <a href=
|
|
"http://www.w3.org/XML/Query/">XML Query Working Group</a>, which
|
|
is part of the <a href="http://www.w3.org/XML/Activity">XML
|
|
Activity</a>. The Working Group expects to eventually publish this
|
|
document as a Working Group Note.</p>
|
|
<p>This document provides a number of use cases designed to
|
|
evaluate the language defined in <a href=
|
|
"http://www.w3.org/TR/xquery-sx-10/">XQuery Scripting Extension
|
|
1.0</a> at the time that it was issued as a Working Draft on 28
|
|
March 2008. Organizations and individuals should review this
|
|
document to ascertain whether or not adequate coverage of the
|
|
requirements is provided by these use cases.</p>
|
|
<p>This document incorporates changes made against the previous
|
|
publication of the Working Draft of 28 March 2008. Changes to this
|
|
document since the previous publication of the Working Draft are
|
|
detailed in <a href="#id-revisions-log"><b>B Revision
|
|
Log</b></a>.</p>
|
|
<p>Please report errors in this document using W3C's <a href=
|
|
"http://www.w3.org/Bugs/Public/">public Bugzilla system</a>
|
|
(instructions can be found at <a href=
|
|
"http://www.w3.org/XML/2005/04/qt-bugzilla">http://www.w3.org/XML/2005/04/qt-bugzilla</a>).
|
|
If access to that system is not feasible, you may send your
|
|
comments to the W3C XSLT/XPath/XQuery public comments mailing list,
|
|
<a href=
|
|
"mailto:public-qt-comments@w3.org">public-qt-comments@w3.org</a>.
|
|
It will be very helpful if you include the string “[SXUC]” in the
|
|
subject line of your report, whether made in Bugzilla or in email.
|
|
Please use multiple Bugzilla entries (or, if necessary, multiple
|
|
email messages) if you have more than one comment to make. Archives
|
|
of the comments and responses are available at <a href=
|
|
"http://lists.w3.org/Archives/Public/public-qt-comments/">http://lists.w3.org/Archives/Public/public-qt-comments/</a>.</p>
|
|
<p>Publication as a Working Draft does not imply endorsement by the
|
|
W3C Membership. This is a draft document and may be updated,
|
|
replaced or obsoleted by other documents at any time. It is
|
|
inappropriate to cite this document as other than work in
|
|
progress.</p>
|
|
<p>This document was produced by a group operating under the
|
|
<a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5
|
|
February 2004 W3C Patent Policy</a>. W3C maintains a <a href=
|
|
"http://www.w3.org/2004/01/pp-impl/18797/status#disclosures">public
|
|
list of any patent disclosures</a> made in connection with the
|
|
deliverables of the group; that page also includes instructions for
|
|
disclosing a patent. An individual who has actual knowledge of a
|
|
patent which the individual believes contains <a href=
|
|
"http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">
|
|
Essential Claim(s)</a> must disclose the information in accordance
|
|
with <a href=
|
|
"http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">
|
|
section 6 of the W3C Patent Policy</a>.</p>
|
|
</div>
|
|
<div class="toc">
|
|
<h2><a name="contents" id="contents"></a>Table of Contents</h2>
|
|
<p class="toc">1 <a href="#use-cases-for-xquery-sx">Use Cases for
|
|
XQuery Scripting Extension</a><br />
|
|
    1.1 <a href="#rdb">Use Case "R" - Scripting
|
|
Relational Data</a><br />
|
|
        1.1.1 <a href=
|
|
"#rdb-dtd">Document Type Definition (DTD)</a><br />
|
|
            1.1.1.1
|
|
<a href="#dtd-for-usres.xml">DTD for users.xml</a><br />
|
|
            1.1.1.2
|
|
<a href="#dtd-for-items.xml">DTD for items.xml</a><br />
|
|
            1.1.1.3
|
|
<a href="#dtd-for-bids.xml">DTD for bids.xml</a><br />
|
|
        1.1.2 <a href=
|
|
"#rdb-data">Input Data</a><br />
|
|
        1.1.3 <a href=
|
|
"#rdb-sx-results">Queries and Results</a><br />
|
|
            1.1.3.1
|
|
<a href="#rdb-sx-results-q1">Q1</a><br />
|
|
            1.1.3.2
|
|
<a href="#rdb-sx-results-q2">Q2</a><br />
|
|
            1.1.3.3
|
|
<a href="#rdb-sx-results-q3">Q3</a><br />
|
|
            1.1.3.4
|
|
<a href="#rdb-sx-results-q4">Q4</a><br />
|
|
    1.2 <a href="#xhtml">Use Case "XHTML" -
|
|
AJAX Scripting with XHTML</a><br />
|
|
        1.2.1 <a href=
|
|
"#xhtml-data">Input Data</a><br />
|
|
        1.2.2 <a href=
|
|
"#xhtml-sx-results">Queries and Results</a><br />
|
|
            1.2.2.1
|
|
<a href="#xhtml-sx-results-q1">Q1</a><br />
|
|
            1.2.2.2
|
|
<a href="#xhtml-sx-results-q2">Q2</a><br />
|
|
    1.3 <a href="#webservice">Use Case "WS" -
|
|
XQuery for Web Services</a><br />
|
|
        1.3.1 <a href=
|
|
"#webservice-data">Input Data</a><br />
|
|
        1.3.2 <a href=
|
|
"#webservice-sx-results">Queries and Results</a><br />
|
|
            1.3.2.1
|
|
<a href="#webservice-sx-results-q1">Q1</a><br />
|
|
            1.3.2.2
|
|
<a href="#webservice-sx-results-q2">Q2</a><br /></p>
|
|
<h3><a name="appendices" id="appendices"></a>Appendices</h3>
|
|
<p class="toc">A <a href="#references">Normative
|
|
References</a><br />
|
|
B <a href="#id-revisions-log">Revision Log</a>
|
|
(Non-Normative)<br />
|
|
    B.1 <a href="#id-log-pending">Changes in
|
|
internal WD</a><br /></p>
|
|
</div>
|
|
<hr />
|
|
<div class="body">
|
|
<div class="div1">
|
|
<h2><a name="use-cases-for-xquery-sx" id=
|
|
"use-cases-for-xquery-sx"></a>1 Use Cases for XQuery Scripting
|
|
Extension</h2>
|
|
<p>The use cases listed below were created by the <a href=
|
|
"http://www.w3.org/XML/Query/">XML Query Working Group</a> to
|
|
illustrate important applications for an XQuery scripting
|
|
extension.</p>
|
|
<div class="div2">
|
|
<h3><a name="rdb" id="rdb"></a>1.1 Use Case "R" - Scripting
|
|
Relational Data</h3>
|
|
<p>This use case is based on performing updates on the data used in
|
|
Use Case "R" from the <a href="#XQueryUseCases">[XML Query Use
|
|
Cases]</a>. The DTD and sample data from this Use Case are copied
|
|
below for convenience, and exactly match those found in the XQuery
|
|
Use Cases.</p>
|
|
<p>The data represents a relational database used by an online
|
|
auction. The auction maintains a USERS table containing information
|
|
on registered users, each identified by a unique userid, who can
|
|
either offer items for sale or bid on items. An ITEMS table lists
|
|
items currently or recently for sale, with the userid of the user
|
|
who offered each item. A BIDS table contains all bids on record,
|
|
keyed by the userid of the bidder and the item number of the item
|
|
to which the bid applies.</p>
|
|
<p>The three tables used by the online auction are below, with
|
|
their column-names indicated in parentheses.</p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
USERS ( USERID, NAME, RATING )
|
|
ITEMS ( ITEMNO, DESCRIPTION, OFFERED_BY,
|
|
START_DATE, END_DATE, RESERVE_PRICE )
|
|
BIDS ( USERID, ITEMNO, BID, BID_DATE )
|
|
</pre></div>
|
|
<div class="div3">
|
|
<h4><a name="rdb-dtd" id="rdb-dtd"></a>1.1.1 Document Type
|
|
Definition (DTD)</h4>
|
|
<p>This use case is based on three separate input documents named
|
|
users.xml, items.xml, and bids.xml. Each of the documents
|
|
represents one of the tables in the relational database described
|
|
above, using the following DTDs:</p>
|
|
<div class="div4">
|
|
<h5><a name="dtd-for-usres.xml" id="dtd-for-usres.xml"></a>1.1.1.1
|
|
DTD for users.xml</h5>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
|
|
<!ELEMENT users (user_tuple*)>
|
|
<!ELEMENT user_tuple (userid, name, rating?)>
|
|
<!ELEMENT userid (#PCDATA)>
|
|
<!ELEMENT name (#PCDATA)>
|
|
<!ELEMENT rating (#PCDATA)>
|
|
|
|
</pre></div>
|
|
</div>
|
|
<div class="div4">
|
|
<h5><a name="dtd-for-items.xml" id="dtd-for-items.xml"></a>1.1.1.2
|
|
DTD for items.xml</h5>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
|
|
<!ELEMENT items (item_tuple*)>
|
|
<!ELEMENT item_tuple (itemno, description, offered_by,
|
|
start_date?, end_date?, reserve_price?)>
|
|
<!ELEMENT itemno (#PCDATA)>
|
|
<!ELEMENT description (#PCDATA)>
|
|
<!ELEMENT offered_by (#PCDATA)>
|
|
<!ELEMENT start_date (#PCDATA)>
|
|
<!ELEMENT end_date (#PCDATA)>
|
|
<!ELEMENT reserve_price (#PCDATA)>
|
|
</pre></div>
|
|
</div>
|
|
<div class="div4">
|
|
<h5><a name="dtd-for-bids.xml" id="dtd-for-bids.xml"></a>1.1.1.3
|
|
DTD for bids.xml</h5>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
|
|
<!ELEMENT bids (bid_tuple*)>
|
|
<!ELEMENT bid_tuple (userid, itemno, bid, bid_date)>
|
|
<!ELEMENT userid (#PCDATA)>
|
|
<!ELEMENT itemno (#PCDATA)>
|
|
<!ELEMENT bid (#PCDATA)>
|
|
<!ELEMENT bid_date (#PCDATA)>
|
|
|
|
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
<div class="div3">
|
|
<h4><a name="rdb-data" id="rdb-data"></a>1.1.2 Input Data</h4>
|
|
<p>Here is an abbreviated set of data showing the XML format of the
|
|
instances:</p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<items>
|
|
<item_tuple>
|
|
<itemno>1001</itemno>
|
|
<description>Red Bicycle</description>
|
|
<offered_by>U01</offered_by>
|
|
<start_date>1999-01-05</start_date>
|
|
<end_date>1999-01-20</end_date>
|
|
<reserve_price>40</reserve_price>
|
|
</item_tuple>
|
|
<em> ... Snip ... </em>
|
|
</items>
|
|
<users>
|
|
<user_tuple>
|
|
<userid>U01</userid>
|
|
<name>Tom Jones</name>
|
|
<rating>B</rating>
|
|
</user_tuple>
|
|
<em> ... Snip ... </em>
|
|
</users>
|
|
<bids>
|
|
<bid_tuple>
|
|
<userid>U02</userid>
|
|
<itemno>1001</itemno>
|
|
<bid>35</bid>
|
|
<bid_date>1999-01-07</bid_date>
|
|
</bid_tuple>
|
|
<bid_tuple>
|
|
<em> ... Snip ... </em>
|
|
</bids>
|
|
|
|
</pre></div>
|
|
<p>The entire data set is represented by the following table:</p>
|
|
<table border="1" summary="Data set table">
|
|
<caption>USERS</caption>
|
|
<thead>
|
|
<tr>
|
|
<td>USERID</td>
|
|
<td>NAME</td>
|
|
<td>RATING</td>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>U01</td>
|
|
<td>Tom Jones</td>
|
|
<td>B</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U02</td>
|
|
<td>Mary Doe</td>
|
|
<td>A</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U03</td>
|
|
<td>Dee Linquent</td>
|
|
<td>D</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U04</td>
|
|
<td>Roger Smith</td>
|
|
<td>C</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U05</td>
|
|
<td>Jack Sprat</td>
|
|
<td>B</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U06</td>
|
|
<td>Rip Van Winkle</td>
|
|
<td>B</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<table border="1" summary="Data set table">
|
|
<caption>ITEMS</caption>
|
|
<thead>
|
|
<tr>
|
|
<td>ITEMNO</td>
|
|
<td>DESCRIPTION</td>
|
|
<td>OFFERED_BY</td>
|
|
<td>START_DATE</td>
|
|
<td>END_DATE</td>
|
|
<td>RESERVE_PRICE</td>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>1001</td>
|
|
<td>Red Bicycle</td>
|
|
<td>U01</td>
|
|
<td>1999-01-05</td>
|
|
<td>1999-01-20</td>
|
|
<td>40</td>
|
|
</tr>
|
|
<tr>
|
|
<td>1002</td>
|
|
<td>Motorcycle</td>
|
|
<td>U02</td>
|
|
<td>1999-02-11</td>
|
|
<td>1999-03-15</td>
|
|
<td>500</td>
|
|
</tr>
|
|
<tr>
|
|
<td>1003</td>
|
|
<td>Old Bicycle</td>
|
|
<td>U02</td>
|
|
<td>1999-01-10</td>
|
|
<td>1999-02-20</td>
|
|
<td>25</td>
|
|
</tr>
|
|
<tr>
|
|
<td>1004</td>
|
|
<td>Tricycle</td>
|
|
<td>U01</td>
|
|
<td>1999-02-25</td>
|
|
<td>1999-03-08</td>
|
|
<td>15</td>
|
|
</tr>
|
|
<tr>
|
|
<td>1005</td>
|
|
<td>Tennis Racket</td>
|
|
<td>U03</td>
|
|
<td>1999-03-19</td>
|
|
<td>1999-04-30</td>
|
|
<td>20</td>
|
|
</tr>
|
|
<tr>
|
|
<td>1006</td>
|
|
<td>Helicopter</td>
|
|
<td>U03</td>
|
|
<td>1999-05-05</td>
|
|
<td>1999-05-25</td>
|
|
<td>50000</td>
|
|
</tr>
|
|
<tr>
|
|
<td>1007</td>
|
|
<td>Racing Bicycle</td>
|
|
<td>U04</td>
|
|
<td>1999-01-20</td>
|
|
<td>1999-02-20</td>
|
|
<td>200</td>
|
|
</tr>
|
|
<tr>
|
|
<td>1008</td>
|
|
<td>Broken Bicycle</td>
|
|
<td>U01</td>
|
|
<td>1999-02-05</td>
|
|
<td>1999-03-06</td>
|
|
<td>25</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<table border="1" summary="Data set table">
|
|
<caption>BIDS</caption>
|
|
<thead>
|
|
<tr>
|
|
<td>USERID</td>
|
|
<td>ITEMNO</td>
|
|
<td>BID</td>
|
|
<td>BID_DATE</td>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>U02</td>
|
|
<td>1001</td>
|
|
<td>35</td>
|
|
<td>1999-01-07</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U04</td>
|
|
<td>1001</td>
|
|
<td>40</td>
|
|
<td>1999-01-08</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U02</td>
|
|
<td>1001</td>
|
|
<td>45</td>
|
|
<td>1999-01-11</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U04</td>
|
|
<td>1001</td>
|
|
<td>50</td>
|
|
<td>1999-01-13</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U02</td>
|
|
<td>1001</td>
|
|
<td>55</td>
|
|
<td>1999-01-15</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U01</td>
|
|
<td>1002</td>
|
|
<td>400</td>
|
|
<td>1999-02-14</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U02</td>
|
|
<td>1002</td>
|
|
<td>600</td>
|
|
<td>1999-02-16</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U03</td>
|
|
<td>1002</td>
|
|
<td>800</td>
|
|
<td>1999-02-17</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U04</td>
|
|
<td>1002</td>
|
|
<td>1000</td>
|
|
<td>1999-02-25</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U02</td>
|
|
<td>1002</td>
|
|
<td>1200</td>
|
|
<td>1999-03-02</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U04</td>
|
|
<td>1003</td>
|
|
<td>15</td>
|
|
<td>1999-01-22</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U05</td>
|
|
<td>1003</td>
|
|
<td>20</td>
|
|
<td>1999-02-03</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U01</td>
|
|
<td>1004</td>
|
|
<td>40</td>
|
|
<td>1999-03-05</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U03</td>
|
|
<td>1007</td>
|
|
<td>175</td>
|
|
<td>1999-01-25</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U05</td>
|
|
<td>1007</td>
|
|
<td>200</td>
|
|
<td>1999-02-08</td>
|
|
</tr>
|
|
<tr>
|
|
<td>U04</td>
|
|
<td>1007</td>
|
|
<td>225</td>
|
|
<td>1999-02-12</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="div3">
|
|
<h4><a name="rdb-sx-results" id="rdb-sx-results"></a>1.1.3 Queries
|
|
and Results</h4>
|
|
<div class="div4">
|
|
<h5><a name="rdb-sx-results-q1" id="rdb-sx-results-q1"></a>1.1.3.1
|
|
Q1</h5>
|
|
<p>Insert a new bid for Roger Smith on item 1002, adding 10% to the
|
|
best bid received so far for this item, and report back what bid
|
|
was just entered.</p>
|
|
<p><em>Solution in the XQuery Scripting Extension:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
let $uid := doc("users.xml")/users/user_tuple[name = "Roger Smith"]/userid
|
|
let $topbid := max(doc("bids.xml")/bids/bid_tuple[itemno = 1002]/bid)
|
|
let $newbid := $topbid * 1.1
|
|
return (
|
|
insert nodes
|
|
<bid_tuple>
|
|
<userid>{ data($uid) }</userid>
|
|
<itemno>1002</itemno>
|
|
<bid>{ $newbid }</bid>
|
|
<bid_date>1999-03-03</bid_date>
|
|
</bid_tuple>
|
|
into doc("bids.xml")/bids,
|
|
<new_bid>{ $newbid }</new_bid>
|
|
)
|
|
|
|
</pre></div>
|
|
<p><em>Expected Result:</em></p>
|
|
<p>The best bid for item 1002 had been at 1200, thus Roger's bid is
|
|
at 1320.</p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<new_bid>1320</new_bid>
|
|
|
|
</pre></div>
|
|
<p><em>Expected resulting content of bids.xml:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<bids>
|
|
<bid_tuple>
|
|
<userid>U02</userid>
|
|
<itemno>1001</itemno>
|
|
<bid>35</bid>
|
|
<bid_date>1999-01-07</bid_date>
|
|
</bid_tuple>
|
|
<em> ... Snip ... </em>
|
|
<bid_tuple>
|
|
<userid>U01</userid>
|
|
<itemno>1002</itemno>
|
|
<bid>400</bid>
|
|
<bid_date>1999-02-14</bid_date>
|
|
</bid_tuple>
|
|
<em> ... Snip ... </em>
|
|
<bid_tuple>
|
|
<userid>U04</userid>
|
|
<itemno>1007</itemno>
|
|
<bid>225</bid>
|
|
<bid_date>1999-02-12</bid_date>
|
|
</bid_tuple>
|
|
<em> ... Snip ... </em>
|
|
<bid_tuple>
|
|
<userid>U04</userid>
|
|
<itemno>1002</itemno>
|
|
<bid>1320</bid>
|
|
<bid_date>1999-03-03</bid_date>
|
|
</bid_tuple>
|
|
</bids>
|
|
|
|
</pre></div>
|
|
</div>
|
|
<div class="div4">
|
|
<h5><a name="rdb-sx-results-q2" id="rdb-sx-results-q2"></a>1.1.3.2
|
|
Q2</h5>
|
|
<p>Place a bid for Roger Smith on item 1007, adding 10% to the best
|
|
bid received so far on that item, but only if the bid amount does
|
|
not exceed a given limit. Otherwise return the current top bid.</p>
|
|
<p><em>Solution in the XQuery Scripting Extension:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
let $uid := doc("users.xml")/users/user_tuple[name = "Roger Smith"]/userid
|
|
let $topbid := max(doc("bids.xml")/bids/bid_tuple[itemno = 1007]/bid)
|
|
let $newbid := $topbid * 1.1
|
|
return
|
|
if($newbid <= 240) then (
|
|
insert nodes
|
|
<bid_tuple>
|
|
<userid>{ data($uid) }</userid>
|
|
<itemno>1002</itemno>
|
|
<bid>{ $newbid }</bid>
|
|
<bid_date>1999-03-03</bid_date>
|
|
</bid_tuple>
|
|
into doc("bids.xml")/bids,
|
|
<new_bid>{ $newbid }</new_bid>
|
|
) else (
|
|
<top_bid>{ $topbid }</top_bid>
|
|
)
|
|
|
|
</pre></div>
|
|
<p><em>Expected Result:</em></p>
|
|
<p>Adding 10% to the best bid on item 1007 would require a bid of
|
|
247.5, which is more than the allowed limit of 240. Thus, the
|
|
bids.xml document does not change.</p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<top_bid>225</top_bid>
|
|
|
|
</pre></div>
|
|
</div>
|
|
<div class="div4">
|
|
<h5><a name="rdb-sx-results-q3" id="rdb-sx-results-q3"></a>1.1.3.3
|
|
Q3</h5>
|
|
<p>Erase user Dee Linquent and the corresponding associated items
|
|
and bids. Return a count of the items and bids deleted.</p>
|
|
<p><em>Solution in the XQuery Scripting Extension:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
let $user := doc("users.xml")/users/user_tuple[name = "Dee Linquent"]
|
|
let $items := doc("items.xml")/items/item_tuple[offered_by = $user/userid]
|
|
let $bids := doc("bids.xml")/bids/bid_tuple[userid = $user/userid]
|
|
return (
|
|
delete nodes ($user, $items, $bids),
|
|
<deleted>
|
|
<items>{ count($items) }</items>
|
|
<bids>{ count($bids) }</bids>
|
|
</deleted>
|
|
)
|
|
</pre></div>
|
|
<p><em>Expected Result:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<deleted>
|
|
<items>2</items>
|
|
<bids>2</bids>
|
|
</deleted>
|
|
</pre></div>
|
|
<p><em>Expected resulting content of items.xml:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<items>
|
|
<item_tuple>
|
|
<itemno>1001</itemno>
|
|
<description>Red Bicycle</description>
|
|
<offered_by>U01</offered_by>
|
|
<start_date>1999-01-05</start_date>
|
|
<end_date>1999-01-20</end_date>
|
|
<reserve_price>40</reserve_price>
|
|
</item_tuple>
|
|
<em> ... Snip ... </em>
|
|
<item_tuple>
|
|
<itemno>1004</itemno>
|
|
<description>Tricycle</description>
|
|
<offered_by>U01</offered_by>
|
|
<start_date>1999-02-25</start_date>
|
|
<end_date>1999-03-08</end_date>
|
|
<reserve_price>15</reserve_price>
|
|
</item_tuple>
|
|
<item_tuple>
|
|
<itemno>1007</itemno>
|
|
<description>Racing bicycle</description>
|
|
<offered_by>U04</offered_by>
|
|
<start_date>1999-01-20</start_date>
|
|
<end_date>1999-02-20</end_date>
|
|
<reserve_price>200</reserve_price>
|
|
</item_tuple>
|
|
<item_tuple>
|
|
<itemno>1008</itemno>
|
|
<description>Broken bicycle</description>
|
|
<offered_by>U01</offered_by>
|
|
<start_date>1999-02-05</start_date>
|
|
<end_date>1999-03-06</end_date>
|
|
<reserve_price>25</reserve_price>
|
|
</item_tuple>
|
|
</items>
|
|
</pre></div>
|
|
<p><em>Expected resulting content of users.xml:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<users>
|
|
<user_tuple>
|
|
<userid>U01</userid>
|
|
<name>Tom Jones</name>
|
|
<rating>B</rating>
|
|
</user_tuple>
|
|
<user_tuple>
|
|
<userid>U02</userid>
|
|
<name>Mary Doe</name>
|
|
<rating>A</rating>
|
|
</user_tuple>
|
|
<user_tuple>
|
|
<userid>U04</userid>
|
|
<name>Roger Smith</name>
|
|
<rating>C</rating>
|
|
</user_tuple>
|
|
<em> ... Snip ... </em>
|
|
<user_tuple>
|
|
<userid>U06</userid>
|
|
<name>Rip Van Winkle</name>
|
|
<rating>B</rating>
|
|
</user_tuple>
|
|
</users>
|
|
</pre></div>
|
|
<p><em>Expected resulting content of bids.xml:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<bids>
|
|
<bid_tuple>
|
|
<userid>U02</userid>
|
|
<itemno>1001</itemno>
|
|
<bid>35</bid>
|
|
<bid_date>1999-01-07</bid_date>
|
|
</bid_tuple>
|
|
<bid_tuple>
|
|
<userid>U04</userid>
|
|
<itemno>1001</itemno>
|
|
<bid>40</bid>
|
|
<bid_date>1999-01-08</bid_date>
|
|
</bid_tuple>
|
|
<em> ... Snip ... </em>
|
|
<bid_tuple>
|
|
<userid>U02</userid>
|
|
<itemno>1002</itemno>
|
|
<bid>600</bid>
|
|
<bid_date>1999-02-16</bid_date>
|
|
</bid_tuple>
|
|
<bid_tuple>
|
|
<userid>U04</userid>
|
|
<itemno>1002</itemno>
|
|
<bid>1000</bid>
|
|
<bid_date>1999-02-25</bid_date>
|
|
</bid_tuple>
|
|
<em> ... Snip ... </em>
|
|
<bid_tuple>
|
|
<userid>U04</userid>
|
|
<itemno>1007</itemno>
|
|
<bid>225</bid>
|
|
<bid_date>1999-02-12</bid_date>
|
|
</bid_tuple>
|
|
</bids>
|
|
|
|
</pre></div>
|
|
</div>
|
|
<div class="div4">
|
|
<h5><a name="rdb-sx-results-q4" id="rdb-sx-results-q4"></a>1.1.3.4
|
|
Q4</h5>
|
|
<p>Monitor the bidding on the helicopter. If Roger Smith does not
|
|
have the current highest bid, add a bid for him that is one higher
|
|
than the top bid, unless the bid amount exceeds a given limit. Stop
|
|
monitoring when the auction has finished.</p>
|
|
<p><em>Solution in the XQuery Scripting Extension:</em></p>
|
|
<table border="1" summary="Editorial note">
|
|
<tr>
|
|
<td align="left" valign="top" width="50%"><b>Editorial
|
|
note</b></td>
|
|
<td align="right" valign="top" width="50%">2008-01-25</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2" align="left" valign="top">A naive execution of this
|
|
query would form a busy loop waiting for the auction to end. This
|
|
is not very desirable, so it's possible an alternative solution
|
|
should be found.</td>
|
|
</tr>
|
|
</table>
|
|
<table border="1" summary="Editorial note">
|
|
<tr>
|
|
<td align="left" valign="top" width="50%"><b>Editorial
|
|
note</b></td>
|
|
<td align="right" valign="top" width="50%">2008-01-25</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2" align="left" valign="top">The fn:current-date()
|
|
function is defined by XQuery as <a href=
|
|
"http://www.w3.org/TR/xpath-functions/#stable">"stable"</a>. This
|
|
means that the query's current dateTime/date/time will not change
|
|
for the duration of the query. It needs to be decided if we intend
|
|
queries to be able to have a notion of time passing, possibly by
|
|
defining the "execution scope" differently for scripting.</td>
|
|
</tr>
|
|
</table>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
declare variable $uid := doc("users.xml")/users/user_tuple
|
|
[name = "Roger Smith"]/userid;
|
|
declare variable $item := doc("items.xml")/items/item_tuple
|
|
[description = "Helicopter"];
|
|
declare variable $result :=
|
|
"Error: The auction has already ended or no bids were placed";
|
|
declare variable $maximumExceeded := false();
|
|
|
|
while(xs:date($item/end_date) >= fn:current-date() and not($maximumExceeded)) {
|
|
let $bids := doc("bids.xml")/bids/bid_tuple[itemno = $item/itemno]
|
|
let $topbid := max($bids/bid)
|
|
let $newbid = $topbid + 1
|
|
where $bids[bid = $topbid]/userid != $uid
|
|
return
|
|
if($newbid <= 60000) then (
|
|
insert nodes
|
|
<bid_tuple>
|
|
{ $uid, $item/itemno }
|
|
<bid>{ $newbid }</bid>
|
|
<bid_date>{ fn:current-date() }</bid_date>
|
|
</bid_tuple>
|
|
into doc("bids.xml")/bids;
|
|
set $result := concat("What a bargain! You got a helicopter for ",
|
|
$newbid);
|
|
) else (
|
|
set $result := "Bidding exceeded 60000";
|
|
set $maximumExceeded := true();
|
|
)
|
|
};
|
|
|
|
$result;
|
|
</pre></div>
|
|
<p><em>Expected Result:</em></p>
|
|
<p>Since this document was published after the end date for the
|
|
auction ("1999-05-25"), the while loop will never be executed.</p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
Error: The auction has already ended or no bids were placed
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="div2">
|
|
<h3><a name="xhtml" id="xhtml"></a>1.2 Use Case "XHTML" - AJAX
|
|
Scripting with XHTML</h3>
|
|
<p>XQuery is ideally suited to manipulating the XML trees of XHTML.
|
|
This use case speculates that XQuery could be used in the way
|
|
Javascript is now, to modify an XHTML web page whilst it is being
|
|
displayed. In this way XQuery can be used to implement effects like
|
|
those commonly referred to by the acronym AJAX.</p>
|
|
<p>This use case deals with a web page that can be used to perform
|
|
a search in a book database. In all queries, there is an assumption
|
|
that the xhtml document is supplied as the context item.</p>
|
|
<div class="div3">
|
|
<h4><a name="xhtml-data" id="xhtml-data"></a>1.2.1 Input Data</h4>
|
|
<p>The starting state of the web page consists of only a simple
|
|
XHTML form.</p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>Book Search</title>
|
|
</head>
|
|
<body>
|
|
<form>
|
|
Book Name: <input type="text" id="txtBookName"/>
|
|
<input type="button" id="btnSend" value="Start Search"/>
|
|
</form>
|
|
</body>
|
|
</html>
|
|
</pre></div>
|
|
</div>
|
|
<div class="div3">
|
|
<h4><a name="xhtml-sx-results" id="xhtml-sx-results"></a>1.2.2
|
|
Queries and Results</h4>
|
|
<div class="div4">
|
|
<h5><a name="xhtml-sx-results-q1" id=
|
|
"xhtml-sx-results-q1"></a>1.2.2.1 Q1</h5>
|
|
<p>Write a script to act as an "onclick" event handler for the
|
|
"btnSend" form button. The script calls a web service to search for
|
|
the book entered by the user and retrieve detailed information for
|
|
the book. While the user is waiting for the web service the message
|
|
"Loading Book" is displayed. This message is later replaced with
|
|
the detailed information for the book.</p>
|
|
<p><em>Input web page:</em></p>
|
|
<p>The web browser has already updated the content of the form's
|
|
text input with the user's search string, "XQuery".</p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>Book Search</title>
|
|
</head>
|
|
<body>
|
|
<form>
|
|
Book Name: <input type="text" id="txtBookName">XQuery</input>
|
|
<input type="button" id="btnSend" value="Start Search"/>
|
|
</form>
|
|
</body>
|
|
</html>
|
|
</pre></div>
|
|
<p><em>Solution in the XQuery Scripting Extension:</em></p>
|
|
<p>The element that caused the event is supplied as an external
|
|
variable called $eventNode. The web service is called using the
|
|
external functions "book:search", and "book:get".</p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
declare namespace xhtml="http://www.w3.org/1999/xhtml";
|
|
declare namespace book="http://www.example.com/booksearch";
|
|
|
|
declare simple function book:search($name as xs:string) as element(book)* external;
|
|
declare simple function book:get($isbn as xs:string) as element(bookinfo) external;
|
|
|
|
declare variable $eventNode as element() external;
|
|
declare $searchResults := ();
|
|
|
|
insert node <xhtml:div>Loading Book</xhtml:div>
|
|
after /xhtml:html/xhtml:body/xhtml:form;
|
|
|
|
set $searchResults :=
|
|
book:search($eventNode/preceding-sibling::xhtml:input[1]);
|
|
|
|
if($searchResults) then (
|
|
replace node /xhtml:html/xhtml:body/xhtml:div
|
|
with <xhtml:div>{
|
|
book:get($searchResults[1]/isbn)/html/node()
|
|
}</xhtml:div>;
|
|
)
|
|
else (
|
|
replace node /xhtml:html/xhtml:body/xhtml:div
|
|
with <xhtml:div>No books found!</xhtml:div>;
|
|
)
|
|
</pre></div>
|
|
<p><em>Results returned to the query from the function call
|
|
book:search("XQuery"):</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<book>
|
|
<title>XQuery from the Experts: A Guide to the W3C XML Query Language</title>
|
|
<isbn>0321180607</isbn>
|
|
</book>
|
|
<book>
|
|
<title>XQuery: The XML Query Language</title>
|
|
<isbn>0321165810</isbn>
|
|
</book>
|
|
</pre></div>
|
|
<p><em>Results returned to the query from the function call
|
|
book:get("0321180607"):</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<bookinfo>
|
|
<title>XQuery from the Experts: A Guide to the W3C XML Query Language</title>
|
|
<isbn>0321180607</isbn>
|
|
<html>
|
|
<h2 xmlns="http://www.w3.org/1999/xhtml">XQuery from the Experts: A Guide to the W3C XML Query Language</h2>
|
|
ISBN: 0321180607
|
|
</html>
|
|
</bookinfo>
|
|
</pre></div>
|
|
<p><em>Expected intermediate content of the web page:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>Book Search</title>
|
|
</head>
|
|
<body>
|
|
<form>
|
|
Book Name: <input type="text" id="txtBookName">XQuery</input>
|
|
<input type="button" id="btnSend" value="Start Search"/>
|
|
</form>
|
|
<xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml">Loading book</xhtml:div>
|
|
</body>
|
|
</html>
|
|
</pre></div>
|
|
<p><em>Expected resulting content of the web page:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>Book Search</title>
|
|
</head>
|
|
<body>
|
|
<form>
|
|
Book Name: <input type="text" id="txtBookName">XQuery</input>
|
|
<input type="button" id="btnSend" value="Start Search"/>
|
|
</form>
|
|
<xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
<h2>XQuery from the Experts: A Guide to the W3C XML Query Language</h2>
|
|
ISBN: 0321180607
|
|
</xhtml:div>
|
|
</body>
|
|
</html>
|
|
</pre></div>
|
|
</div>
|
|
<div class="div4">
|
|
<h5><a name="xhtml-sx-results-q2" id=
|
|
"xhtml-sx-results-q2"></a>1.2.2.2 Q2</h5>
|
|
<p>Write a script to act as an "onclick" event handler for the
|
|
"btnSend" form button. The script calls a web service to search for
|
|
the book entered by the user, and uses an additional web service to
|
|
find which libraries have these books on the shelves. The
|
|
information received is displayed asynchronously as it arrives.</p>
|
|
<p><em>Input web page:</em></p>
|
|
<p>The web browser has already updated the content of the form's
|
|
text input with the user's search string, "XQuery".</p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>Book Search</title>
|
|
</head>
|
|
<body>
|
|
<form>
|
|
Book Name: <input type="text" id="txtBookName">XQuery</input>
|
|
<input type="button" id="btnSend" value="Start Search"/>
|
|
</form>
|
|
</body>
|
|
</html>
|
|
</pre></div>
|
|
<p><em>Solution in the XQuery Scripting Extension:</em></p>
|
|
<p>The element that caused the event is supplied as an external
|
|
variable called $eventNode. The web services are called using the
|
|
external functions "book:search", and "library:find".</p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
declare namespace xhtml="http://www.w3.org/1999/xhtml";
|
|
declare namespace book="http://www.example.com/booksearch";
|
|
declare namespace library="http://www.example.com/library";
|
|
|
|
declare simple function book:search($name as xs:string)
|
|
as element(book)* external;
|
|
declare simple function library:find($isbn as xs:string)
|
|
as element(library)* external;
|
|
|
|
declare variable $eventNode as element() external;
|
|
declare variable $table := ();
|
|
|
|
insert node <xhtml:div><xhtml:table/></xhtml:div>
|
|
after /xhtml:html/xhtml:body/xhtml:form;
|
|
set $table := //xhtml:table;
|
|
|
|
for $book in book:search($eventNode/preceding-sibling::xhtml:input[1])
|
|
return (
|
|
insert node
|
|
<xhtml:tr>
|
|
<xhtml:td>{data($book/title)}</xhtml:td>
|
|
<xhtml:td>{data($book/isbn)}</xhtml:td>
|
|
<xhtml:td/>
|
|
</xhtml:tr>
|
|
as last into $table;
|
|
);
|
|
|
|
for $row in $table/xhtml:tr
|
|
return (
|
|
replace value of node $row/xhtml:td[3]
|
|
with string-join(library:find($row/xhtml:td[2])/name, ", ");
|
|
);
|
|
</pre></div>
|
|
<p><em>Results returned to the query from the function call
|
|
book:search("XQuery"):</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<book>
|
|
<title>XQuery from the Experts: A Guide to the W3C XML Query Language</title>
|
|
<isbn>0321180607</isbn>
|
|
</book>
|
|
<book>
|
|
<title>XQuery: The XML Query Language</title>
|
|
<isbn>0321165810</isbn>
|
|
</book>
|
|
</pre></div>
|
|
<p><em>Results returned to the query from the function call
|
|
library:find("0321180607"):</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<library>
|
|
<name>Bodleian Library</name>
|
|
<url>http://www.bodley.ox.ac.uk/</url>
|
|
<lending>no</lending>
|
|
</library>
|
|
<library>
|
|
<name>Radcliffe Science Library</name>
|
|
<url>http://www.ouls.ox.ac.uk/rsl/</url>
|
|
<lending>yes</lending>
|
|
</library>
|
|
</pre></div>
|
|
<p><em>Results returned to the query from the function call
|
|
library:find("0321165810"):</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<library>
|
|
<name>Radcliffe Science Library</name>
|
|
<url>http://www.ouls.ox.ac.uk/rsl/</url>
|
|
<lending>yes</lending>
|
|
</library>
|
|
</pre></div>
|
|
<p><em>Expected resulting content of the web page:</em></p>
|
|
<p>The web page will be altered as the results are received from
|
|
the web services, but the final result will look like this.</p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>Book Search</title>
|
|
</head>
|
|
<body>
|
|
<form>
|
|
Book Name: <input type="text" id="txtBookName">XQuery</input>
|
|
<input type="button" id="btnSend" value="Start Search"/>
|
|
</form>
|
|
<xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
<xhtml:table>
|
|
<xhtml:tr>
|
|
<xhtml:td>XQuery from the Experts: A Guide to the W3C XML Query Language</xhtml:td>
|
|
<xhtml:td>0321180607</xhtml:td>
|
|
<xhtml:td>Bodleian Library, Radcliffe Science Library</xhtml:td>
|
|
</xhtml:tr>
|
|
<xhtml:tr>
|
|
<xhtml:td>XQuery: The XML Query Language</xhtml:td>
|
|
<xhtml:td>0321165810</xhtml:td>
|
|
<xhtml:td>Radcliffe Science Library</xhtml:td>
|
|
</xhtml:tr>
|
|
</xhtml:table>
|
|
</xhtml:div>
|
|
</body>
|
|
</html>
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="div2">
|
|
<h3><a name="webservice" id="webservice"></a>1.3 Use Case "WS" -
|
|
XQuery for Web Services</h3>
|
|
<p>This use case deals with the implementation of a REST based web
|
|
service, specifically a micro-blog.</p>
|
|
<div class="div3">
|
|
<h4><a name="webservice-data" id="webservice-data"></a>1.3.1 Input
|
|
Data</h4>
|
|
<p>The default collection contains a forest of micro blog
|
|
documents, one for each user. Initially the forest contains these
|
|
documents.</p>
|
|
<p><em>John's micro-blog:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<micro-blog user="john">
|
|
<entry timestamp="2007-10-17T10:02:53+01:00">
|
|
<text>Still reading email...</text>
|
|
</entry>
|
|
<entry timestamp="2007-10-17T20:19:31+01:00">
|
|
<text>Writing XQuery Scripting Extension use cases (ideas, anyone?)</text>
|
|
</entry>
|
|
<entry timestamp="2007-10-18T00:43:02+01:00">
|
|
<text>Thinking of going to bed</text>
|
|
</entry>
|
|
</micro-blog>
|
|
</pre></div>
|
|
<p><em>Emily's micro-blog:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<micro-blog user="emily">
|
|
<entry timestamp="2007-10-16T18:12:51+01:00">
|
|
<text>So how do you use a micro-blog?</text>
|
|
</entry>
|
|
<entry timestamp="2007-10-16T18:13:20+01:00">
|
|
<text>Ah, I see</text>
|
|
</entry>
|
|
<entry timestamp="2007-10-17T07:33:44+01:00">
|
|
<text>Morning, everybody!</text>
|
|
</entry>
|
|
</micro-blog>
|
|
</pre></div>
|
|
<p><em>A document containing the blog access log:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<log>
|
|
</log>
|
|
</pre></div>
|
|
</div>
|
|
<div class="div3">
|
|
<h4><a name="webservice-sx-results" id=
|
|
"webservice-sx-results"></a>1.3.2 Queries and Results</h4>
|
|
<div class="div4">
|
|
<h5><a name="webservice-sx-results-q1" id=
|
|
"webservice-sx-results-q1"></a>1.3.2.1 Q1</h5>
|
|
<p>Process a request from John to add a blog entry, returning a
|
|
confirmation XHTML page.</p>
|
|
<p><em>The element representing the request:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<request>
|
|
<method>POST</method>
|
|
<url>http://blog.example.com/john/add</url>
|
|
<param name="text">Making a post to my XQuery blog engine</param>
|
|
</request>
|
|
</pre></div>
|
|
<p><em>Solution in the XQuery Scripting Extension:</em></p>
|
|
<p>The request element is bound to the external variable
|
|
$request.</p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
declare variable $request as element(request) external;
|
|
|
|
declare simple function local:error($message)
|
|
{
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>Error</title>
|
|
</head>
|
|
<body>
|
|
<h1>Error</h1>
|
|
<p>{ $message }</p>
|
|
</body>
|
|
</html>
|
|
};
|
|
|
|
if($request/method = "POST") then () else
|
|
exit with local:error(concat("You cannot use the ",
|
|
$request/method, " method with this URL."));
|
|
|
|
let $user := replace($request/url, "^http://.*/([^/]+)/add$", "$1")
|
|
let $blog := collection()/micro-blog[@user = $user]
|
|
return (
|
|
if($blog) then () else
|
|
exit with local:error("Unknown user");
|
|
|
|
insert node
|
|
<entry timestamp="{ current-dateTime() }">
|
|
<text>{ $request/param[@name = "text"] }</text>
|
|
</entry>
|
|
as last into $blog;
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>Blog entry added for { $user }</title>
|
|
</head>
|
|
<body>
|
|
<h1>Blog entry added for { $user }</h1>
|
|
<p>{ $request/param[@name = "text"] }</p>
|
|
</body>
|
|
</html>;
|
|
);
|
|
</pre></div>
|
|
<p><em>Expected Result:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>Blog entry added for john</title>
|
|
</head>
|
|
<body>
|
|
<h1>Blog entry added for john</h1>
|
|
<p>Making a post to my XQuery blog engine</p>
|
|
</body>
|
|
</html>
|
|
</pre></div>
|
|
<p><em>Expected resulting content of John's micro-blog:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<micro-blog user="john">
|
|
<entry timestamp="2007-10-17T10:02:53+01:00">
|
|
<text>Still reading email...</text>
|
|
</entry>
|
|
<entry timestamp="2007-10-17T20:19:31+01:00">
|
|
<text>Writing XQuery Scripting Extension use cases (ideas, anyone?)</text>
|
|
</entry>
|
|
<entry timestamp="2007-10-18T00:43:02+01:00">
|
|
<text>Thinking of going to bed</text>
|
|
</entry>
|
|
<entry timestamp="2007-10-18T08:53:9+01:00">
|
|
<text>Making a post to my XQuery blog engine</text>
|
|
</entry>
|
|
</micro-blog>
|
|
</pre></div>
|
|
</div>
|
|
<div class="div4">
|
|
<h5><a name="webservice-sx-results-q2" id=
|
|
"webservice-sx-results-q2"></a>1.3.2.2 Q2</h5>
|
|
<p>Process the same request from John, using a function to check
|
|
that "john" is a valid user name and to log the event.</p>
|
|
<p><em>The element representing the request:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<request>
|
|
<method>POST</method>
|
|
<url>http://blog.example.com/john/add</url>
|
|
<param name="text">Making a post to my XQuery blog engine</param>
|
|
</request>
|
|
</pre></div>
|
|
<p><em>Solution in the XQuery Scripting Extension:</em></p>
|
|
<p>The request element is bound to the external variable
|
|
$request.</p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
declare variable $request as element(request) external;
|
|
|
|
declare sequential function local:check-user-and-log($username as xs:string)
|
|
as element(micro-blog)?
|
|
{
|
|
declare $entry as element() :=
|
|
<access-attempt>
|
|
<timestamp>{fn:current-dateTime()}</timestamp>
|
|
<user-name>{$username}</user-name>
|
|
<access-allowed/>
|
|
</access-attempt>;
|
|
declare $blog as element(micro-blog)? :=
|
|
collection()/micro-blog[@user = $username];
|
|
|
|
if($blog) then
|
|
replace value of node $entry/access-allowed with "Yes"
|
|
else
|
|
replace value of node $entry/access-allowed with "No";
|
|
|
|
insert node $entry as last into collection()/log;
|
|
exit with $blog;
|
|
}
|
|
|
|
|
|
declare simple function local:error($message)
|
|
{
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>Error</title>
|
|
</head>
|
|
<body>
|
|
<h1>Error</h1>
|
|
<p>{ $message }</p>
|
|
</body>
|
|
</html>
|
|
};
|
|
|
|
if($request/method = "POST") then () else
|
|
exit with local:error(concat("You cannot use the ",
|
|
$request/method, " method with this URL."));
|
|
|
|
let $user := replace($request/url, "^http://.*/([^/]+)/add$", "$1")
|
|
let $blog := local:check-user-and-log($user)
|
|
return (
|
|
if($blog) then () else
|
|
exit with local:error("Unknown user");
|
|
|
|
insert node
|
|
<entry timestamp="{ current-dateTime() }">
|
|
<text>{ $request/param[@name = "text"] }</text>
|
|
</entry>
|
|
as last into $blog;
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>Blog entry added for { $user }</title>
|
|
</head>
|
|
<body>
|
|
<h1>Blog entry added for { $user }</h1>
|
|
<p>{ $request/param[@name = "text"] }</p>
|
|
</body>
|
|
</html>;
|
|
);
|
|
</pre></div>
|
|
<p><em>Expected Result:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>Blog entry added for john</title>
|
|
</head>
|
|
<body>
|
|
<h1>Blog entry added for john</h1>
|
|
<p>Making a post to my XQuery blog engine</p>
|
|
</body>
|
|
</html>
|
|
</pre></div>
|
|
<p><em>Expected resulting content of John's micro-blog:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<micro-blog user="john">
|
|
<entry timestamp="2007-10-17T10:02:53+01:00">
|
|
<text>Still reading email...</text>
|
|
</entry>
|
|
<entry timestamp="2007-10-17T20:19:31+01:00">
|
|
<text>Writing XQuery Scripting Extension use cases (ideas, anyone?)</text>
|
|
</entry>
|
|
<entry timestamp="2007-10-18T00:43:02+01:00">
|
|
<text>Thinking of going to bed</text>
|
|
</entry>
|
|
<entry timestamp="2007-10-18T08:53:9+01:00">
|
|
<text>Making a post to my XQuery blog engine</text>
|
|
</entry>
|
|
</micro-blog>
|
|
</pre></div>
|
|
<p><em>Expected resulting content of the log:</em></p>
|
|
<div class="exampleInner">
|
|
<pre>
|
|
<log>
|
|
<access-attempt>
|
|
<timestamp>2007-10-18T08:53:9+01:00</timestamp>
|
|
<user-name>john</user-name>
|
|
<access-allowed>Yes</access-allowed>
|
|
</access-attempt>
|
|
</log>
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="back">
|
|
<div class="div1">
|
|
<h2><a name="references" id="references"></a>A Normative
|
|
References</h2>
|
|
<dl>
|
|
<dt class="label"><span><a name="xquery" id="xquery"></a>XQuery
|
|
1.0</span></dt>
|
|
<dd>
|
|
<div>World Wide Web Consortium. <em>XQuery 1.0: An XML Query
|
|
Language</em>. W3C Recommendation, 23 January 2007. See <a href=
|
|
"http://www.w3.org/TR/xquery/">http://www.w3.org/TR/xquery/</a>.</div>
|
|
</dd>
|
|
<dt class="label"><span><a name="XQueryUseCases" id=
|
|
"XQueryUseCases"></a>XML Query Use Cases</span></dt>
|
|
<dd>
|
|
<div>World Wide Web Consortium. <em>XML Query Use Cases</em>. W3C
|
|
Working Group Note, 23 March 2007. See <a href=
|
|
"http://www.w3.org/TR/xquery-use-cases/">http://www.w3.org/TR/xquery-use-cases/</a>.</div>
|
|
</dd>
|
|
<dt class="label"><span><a name="updatespec" id=
|
|
"updatespec"></a>XQuery Update Facility</span></dt>
|
|
<dd>
|
|
<div>World Wide Web Consortium. <em>XQuery Update Facility</em>.
|
|
W3C Working Draft, 28 August 2007. See <a href=
|
|
"http://www.w3.org/TR/xquery-update-10/">http://www.w3.org/TR/xquery-update-10/</a>.</div>
|
|
</dd>
|
|
<dt class="label"><span><a name="serequirements" id=
|
|
"serequirements"></a>XQuery Scripting Extension 1.0
|
|
Requirements</span></dt>
|
|
<dd>
|
|
<div>World Wide Web Consortium. <em>XQuery Scripting Extension 1.0
|
|
Requirements</em>. W3C Working Draft, 23 March 2007. See <a href=
|
|
"http://www.w3.org/TR/2007/WD-xquery-sx-10-requirements-20070323">http://www.w3.org/TR/2007/WD-xquery-sx-10-requirements-20070323</a>.</div>
|
|
</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="div1">
|
|
<h2><a name="id-revisions-log" id="id-revisions-log"></a>B Revision
|
|
Log (Non-Normative)</h2>
|
|
<p>This log records the substantive changes that have been made to
|
|
this document . Minor editorial changes are not included in this
|
|
log.</p>
|
|
<div class="div2">
|
|
<h3><a name="id-log-pending" id="id-log-pending"></a>B.1 Changes in
|
|
internal WD</h3>
|
|
<ul>
|
|
<li>
|
|
<p>Added an editorial note detailing the problems with RDB Q4.</p>
|
|
</li>
|
|
<li>
|
|
<p>Added the WS Q2 use case.</p>
|
|
</li>
|
|
<li>
|
|
<p>2008-07-10: Updated the syntax to the lastest editor's
|
|
draft.</p>
|
|
</li>
|
|
<li>
|
|
<p>2008-11-09: Updated the syntax to the lastest editor's
|
|
draft.</p>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|