This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.0"; | |
for $trip in collection('/db/cms/apps/travels/data/secretaries')/trips/trip | |
let $duration := xs:date($trip/end-date) - xs:date($trip/start-date) | |
order by $duration descending | |
return <trip duration="{$duration}">{ $trip }</trip> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
(: | |
Receive payloads from BitBucket.org POST hooks with eXist | |
Prerequisites: | |
1. A post-January 2015 build of the develop branch of eXist, which adds support | |
for XQuery 3.1's JSON parsing and serialization features. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let $path-to-xq := '/db/cms/apps/tei-content/views/ebook-batch.xq' | |
return | |
sm:chmod(xs:anyURI($path-to-xq), 'rwxr-xr-x') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
declare namespace html="http://www.w3.org/TR/REC-html40"; (: the version of HTML used by the URL below :) | |
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization"; (: use XQuery 3.1's JSON serialization :) | |
import module namespace http="http://expath.org/ns/http-client"; (: @see http://expath.org/spec/http-client :) | |
declare option output:method "json"; | |
declare option output:media-type "application/json"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
(: parse tweets using XQuery 3.1's JSON support | |
: see http://www.w3.org/TR/xpath-functions-31/#json | |
: sample JSON from https://dev.twitter.com/rest/reference/get/statuses/user_timeline | |
:) | |
let $json := json-doc('/db/user_timeline.json') | |
let $tweets := $json?* | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.0"; | |
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization"; | |
declare option output:method "html5"; | |
declare option output:media-type "text/html"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.0"; | |
(: Display a list of Principal Officers who are still alive who began serving on/after, or were serving as of, January 20, 1977. :) | |
let $all-people := collection('/db/cms/apps/principals-chiefs/data/')/person | |
let $principals := $all-people[.//role/@class='principal'] | |
let $cutoff-date := '1977-01-20' | |
let $since-cutoff := $principals//role[@class='principal'][event[@type=('appointed', 'appointterminated')]/@when ge $cutoff-date]/ancestor::person | |
let $still-living := $since-cutoff[death/@type = 'unknown' or death = '' or empty(death/node())] | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.0"; | |
declare namespace fn="http://www.w3.org/2005/xpath-functions"; | |
(: Fix problems with mis-capitalized names. For example: | |
Before: MACARTHUR, Douglas II | |
After: MacArthur, Douglas II | |
:) | |
declare function local:fix-name-capitalization($name as xs:string) { | |
(: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.0"; | |
(: find the shortest and longest article and get the average word count of a collection of TEI XML articles :) | |
declare namespace tei="http://www.tei-c.org/ns/1.0"; | |
(: in our case, 'articles' are TEI divs that have @xml:id attributes and no child divs; | |
we filter out the foreward since they're not full articles. :) | |
let $milestone-articles := collection('/db/cms/apps/tei-content/data/milestones')//tei:div[@xml:id and not(.//tei:div)][@xml:id ne 'foreword'] | |
let $article-infos := |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.0"; | |
for $ambassador in collection('/db/cms/apps/principals-chiefs/data')/person | |
let $postings := $ambassador/role | |
let $how-many-postings := count($postings) | |
group by $how-many-postings | |
order by $how-many-postings descending | |
return | |
<group postings="{$how-many-postings}" people-in-this-group="{count($ambassador)}"> | |
{ |