Skip to content

Instantly share code, notes, and snippets.

@CliffordAnderson
Created December 22, 2013 19:57
Show Gist options
  • Save CliffordAnderson/8087645 to your computer and use it in GitHub Desktop.
Save CliffordAnderson/8087645 to your computer and use it in GitHub Desktop.
Query for long and short phrases in Shakespeare's plays
xquery version "3.0";
declare namespace tei="http://www.tei-c.org/ns/1.0";
for $result in fn:collection("/db/shakespeare")//tei:ab
let $length :=
if (fn:string-length($result) gt 20) then "long-phrase"
else "short-phrase"
group by $length
return element { $length } { count($result) }
@CliffordAnderson
Copy link
Author

An example of using the "group by" keyword in XQuery 3.0 adapted from the corresponding BaseX documentation example to sort by distinct values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment