Skip to content

Instantly share code, notes, and snippets.

View taoyou's full-sized avatar

Tao You taoyou

  • Vanderbilt University Library
View GitHub Profile
@taoyou
taoyou / facets.xq
Created November 5, 2015 22:56
get facets based on path variable
xquery version "3.1";
declare function local:get_facet ($books as element()*, $path as xs:string ) as element()?
{
<binding>{
for $book in $books
let $fld := $book/*[name()=$path]
group by $f := $fld
@taoyou
taoyou / multi_facets.xq
Created November 6, 2015 19:04
return list of multiple facets
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 := $book/*[name()=$path]
group by $f := $fld
order by $f descending
return element {$facet_type} {attribute v {$f}, attribute number {fn:count($book)} }
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 )
xquery version "3.1";
for $doc in fn:collection("books")/full-text
let $keys := fn:tokenize( fn:base-uri($doc), "/")[4]
for $key in $keys
return fn:collection("books")//key