Skip to content

Instantly share code, notes, and snippets.

@taoyou
Created November 13, 2015 22:36
Show Gist options
  • Save taoyou/3df7f0fb16085d70ce98 to your computer and use it in GitHub Desktop.
Save taoyou/3df7f0fb16085d70ce98 to your computer and use it in GitHub Desktop.
xquery version "3.1";
declare function local:get_facet ($books as element()*, $path as xs:string, $facet_type as xs:string ) as element()?
{
<facet type="{$facet_type}">{
for $book in $books
let $fld :=
let $vars := map{ '': document{$book} }
let $query := "declare namespace tei = 'http://www.tei-c.org/ns/1.0'; " || $path
return xquery:eval($query, $vars )
group by $f := $fld
order by $f descending
return element {$facet_type} {attribute v {$f}, attribute number {fn:count($book)} }
}</facet>
};
let $csv := fetch:text("https://gist.githubusercontent.com/CliffordAnderson/5be754415308dc407fc9/raw/daa23df71ceef375b83dd5b290284f83beeb710b/books.csv")
let $books := csv:parse($csv, map { 'header': true() })/csv/record
return (local:get_facet($books, "//Binding", "Binding" ) )
(: return ($book) :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment