-
-
Save EdWarga/677cdd1e2fec95bcd688 to your computer and use it in GitHub Desktop.
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
<terms> | |
<term> | |
<path>date</path> | |
<facet>date</facet> | |
</term> | |
</terms> |
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 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