[http://creativecommons.org/licenses/by/3.0/]
This work is licensed under a CC
Attribution 3.0 Unported License [http://creativecommons.org/licenses/by/3.0/]
This last part of the XQuery lectures covers some additional XQuery topics and briefly looks into how to create user-defined functions. After that, XML linking methods are considered, specifically xml:id
, XML Inclusions (XInclude), and the XML Linking Language (XLink). These methods are used as a starting point to look at potential XML processing in XQuery, specifically, how to use XQuery code to identify and dereference the links that are used in the XInclude vocabulary.
<a>123</a>, <b>456</b>
doc("books.xml")//author, doc("books.xml")//title
for $b in doc("books.xml")//book return $b/title, $b/author
for $b in doc("books.xml")//book return ( $b/title, $b/author )
declare boundary-space strip; let $a := "Bob Glushko" return <book> <title>Document Engineering</title> <author> { $a } </author> </book>
<book> <title>Document Engineering</title> <author>Bob Glushko</author> <price currency="USD">29.99</price> </book>
element book { element title { "Document Engineering" }, element {concat("author",position($x))} { "Bob Glushko" }, element price { attribute currency { "USD" }, 29.99 } }
declare function local:onetwothree() as xs:integer+ { (1, 2, 3) };
declare function local:format-date($date) { string($date) } ; <html> <body> <table border="1" cellpadding="20"> { for $post in //post return <tr> <td><a href="../img/{ $post/image/@src }.jpg"><img src="../img/{ $post/image/@src }-small.jpg"/></a></td> <td> <h2> { local:format-date($post/@date) }: { $post/title/text() } </h2> <p> { $post/text/text() } </p> </td> </tr> } </table> </body> </html>
link microformatfor XML
and while we're at it, we might as well turn the Web into a proper hypermedia system!
IDnessof an attribute is established by its name
xml:id
uses XML's own namespace to identify identifiershttp://www.w3.org/XML/1998/namespace
[http://www.w3.org/XML/1998/namespace] contains a mix of various specs<section id="introduction">
<section xml:id="introduction">
<x xmlns:xi="http://www.w3.org/2001/XInclude"> <xi:include href="something.xml"/> <xi:include xpointer="xmlns(xi=http://www.w3.org/2001/XInclude)xpointer(x/xi:include[1])" parse="xml"/> </x>
<!ELEMENT xi:include (xi:fallback?)> <!ATTLIST xi:include xmlns:xi CDATA #FIXED "http://www.w3.org/2001/XInclude" href CDATA #IMPLIED parse (xml|text) "xml" xpointer CDATA #IMPLIED encoding CDATA #IMPLIED accept CDATA #IMPLIED accept-language CDATA #IMPLIED >
<a xlink:href="…" [ xlink:actuate="onRequest" xlink:show="replace" ] xlink:type="simple" > … </a>
<a xlink:href="…" [ xlink:role="…" xlink:arcrole="…" xlink:title="…" ] xlink:type="simple" > … </a>
onLoad
instructs to traverse the link as soon as the starting resource is displayedonRequest
waits for link traversal until a user has initiated link traversalother
allows markup extensions, none
specifies that there is no additional informationnew
specifies that a new presentation context is be created (e.g., a new window)replace
specifies that the target resource replaces the current resourceembed
specifies that the target resource replaces the starting resource fragmentother
allows markup extensions, none
specifies that there is no additional informationhttp://www.w3.org/1999/xlink/properties/linkbase
<environment xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="extended"> <artist xlink:type="locator" xlink:role="artist" xlink:href="modigliani.xml"/> <influence xlink:type="locator" xlink:label="inspiration" xlink:href="cezanne.xml"/> <influence xlink:type="locator" xlink:label="inspiration" xlink:href="lautrec.xml"/> <influence xlink:type="locator" xlink:label="inspiration" xlink:href="rouault.xml"/> <history xlink:type="locator" xlink:label="period" xlink:href="paris.xml"/> <history xlink:type="locator" xlink:label="period" xlink:href="kisling.xml"/> <bind xlink:type="arc" xlink:from="artist" xlink:to="inspiration"/> <bind xlink:type="arc" xlink:from="artist" xlink:to="period"/> </environment>