Skip to content

Instantly share code, notes, and snippets.

@EdWarga
Forked from AdamSteffanick/facets.xml
Created November 20, 2015 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdWarga/677cdd1e2fec95bcd688 to your computer and use it in GitHub Desktop.
Save EdWarga/677cdd1e2fec95bcd688 to your computer and use it in GitHub Desktop.
<terms>
<term>
<path>date</path>
<facet>date</facet>
</term>
</terms>
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] (: Check whether name of element matches the string value of $path :)
group by $f := $fld
order by $f descending
return element {$facet_type} {attribute v {$f}, attribute number {fn:count($book)} }
}</facet>
};
let $corpus := fn:collection("fleurs-du-mal")
let $facets := fn:doc("https://gist.githubusercontent.com/AdamSteffanick/ab59d4c20590cfc0213c/raw/68b09633bef948c460d5ed0e36976bdf7ffd0677/facets.xml")
(: return $corpus//*:imprint/*:date/text() :)
for $facet in $facets/terms/term
return local:get_facet($corpus//*:imprint, $facet/path/text(), $facet/facet/text() )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment