Skip to content

Instantly share code, notes, and snippets.

@derickson
derickson / config.xqy
Created December 10, 2011 21:42
Mobile Shakespeare Tutorial Part 1
xquery version "1.0-ml" ;
(: config.xqy
This library module holds configuration
variables for the application
:)
module namespace cfg = "http://framework/lib/config";
(: The rewrite library route configuration
@derickson
derickson / header.html
Created December 12, 2011 03:51
Mobile Shakespeare Tutorial Part 2
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href='http://fonts.googleapis.com/css?family=Aguafina+Script|Vast+Shadow' rel='stylesheet' type='text/css'/>
<link rel="stylesheet" href="/css/mobshake-jm.min.css"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc2/jquery.mobile.structure-1.0rc2.min.css"/>
<link rel="stylesheet" href="/css/mobshake.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.js"></script>
@derickson
derickson / config-snip.xqy
Created December 17, 2011 04:55
Mobile Shakespeare Tutorial Part 3
<get path="play/:id/act/:act/scene/:scene/speech/:speech"><to>play#scene</to></get>
<get path="search"><to>search#get</to></get>
<post path="search"><to>search#get</to></post>
@derickson
derickson / circles.xqy
Created January 6, 2012 04:49
GeoReverseQuery
xquery version "1.0-ml";
(: a whole bunch of random circles to make the reverse-query harder :)
let $n := 10000
for $count in (1 to $n)
let $lat := xdmp:random(180) - 90
let $lon := xdmp:random(360) - 180
let $query-doc :=
@derickson
derickson / event.xml
Created January 10, 2012 05:33
XQuery Choropleth
<?xml version="1.0" encoding="UTF-8"?>
<event>
<name>Bethesda</name>
<point>38.9846520, -77.0947092</point>
</event>
@derickson
derickson / map.xqy
Created January 10, 2012 05:47
XQuery Choropleth complete
xquery version "1.0-ml";
import module namespace search="http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
declare namespace kml = "http://www.opengis.net/kml/2.2";
(:White to red color scale in BBGGRR format :)
declare variable $COLOR_SCALE :=
@derickson
derickson / bookload.xqy
Created May 3, 2012 23:42
Learning XQuery
let $books :=
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
... other books from W3Schools example ...
</bookstore>
@derickson
derickson / bad.xqy
Created May 4, 2012 01:31
Learning XQuery 2
(: I assume local mathematical functions
functionA, functionB, and functionC are
defined above :)
(: this is too procedural :)
let $accumulator := 1
let $accumulator := functionA($accumulator)
let $accumulator := functionB($accumulator)
let $accumulator := functionC($accumulator)
return
@derickson
derickson / xpath.xqy
Created May 4, 2012 01:49
XPath First
//book[author eq "J K. Rowling"]
@derickson
derickson / enrich.xqy
Created May 20, 2012 04:05
Lord of the Rings txt to XML
xquery version "1.0-ml";
for $character in ("Frodo", "Sam", "Merry", "Pippin", "Boromir", "Gimli", "Legolas", "Aragorn", "Gandalf")
return
xdmp:eval('
xquery version"1.0-ml";
declare variable $character as xs:string external;
for $line in cts:search(/line-doc, $character)
return
xdmp:node-replace(