\dontcomplain

\def\MF {MF} \def\MP {MP} \def\TUB{TUGboat} \def\Mc {Mac}
\def\sltt{\tt} \def\acro#1{#1}

\usemodule[abr-01]

\startxmlsetups bibtex
   % todo: messy
   \xmlregistereddocumentsetups{#1}{}
   \xmlsetsetup{#1}{bibtex|c|e|v}{bibtex:*}
   \xmlmain{#1}
\stopxmlsetups

% \xmlregisterdocumentsetup{bibtex:somebibtex}{bibtex:main}

\startxmlsetups bibtex:bibtex
   \xmlfilter{#1}{e/v[@n=='author' and find(text(),'Arafat') or find(text(),'Joyner')]/../command(bibtex:one)}
\stopxmlsetups

\startxmlsetups bibtex:c
\stopxmlsetups

\startxmlsetups bibtex:e
\stopxmlsetups

% \startxmlsetups bibtex:v
%    \xmlflushcontext{#1}
% \stopxmlsetups

\startxmlsetups xml:bibtex:sorter
   \xmlresetsorter{bibtex}
   \xmlfilter{#1}{e/command(bibtex:entry:getkeys)}
   \blank sortkeys: \blank\xmlshowsorter{bibtex}\blank
   \xmlsortentries{bibtex}
   \xmlflushsorter{bibtex}{bibtex:entry:flush}
\stopxmlsetups

\startxmlsetups bibtex:entry:getkeys
   \xmladdsortentry{bibtex}{#1}{\xmlfilter{#1}{/v[@n=='author']/text()}}
   \xmladdsortentry{bibtex}{#1}{\xmlfilter{#1}{/v[@n=='year']/text()}}
   \xmladdsortentry{bibtex}{#1}{\xmlatt{#1}{n}}
\stopxmlsetups

\startxmlsetups bibtex:one
   \starttabulate
   \NC id     \NC \xmlatt{#1}{n} \NC \NR
   \NC author \NC \xmlfilter{#1}{/v[@n=='author']/context()} \NC \NR
   \NC title  \NC \xmlfilter{#1}{/v[@n=='title']/context()} \NC \NR
   \stoptabulate
\stopxmlsetups

\startxmlsetups bibtex:entry:flush
   \xmlfilter{#1}{/v[@n=='author']/context()} / %
   \xmlfilter{#1}{/v[@n=='year']/context()}   / %
   \xmlatt{#1}{n}\par
\stopxmlsetups


\starttext

\definebibtexsession [somebibtex]
% \registerbibtexentry [somebibtex][Hagen:TB26-2-152]
%\registerbibtexfile  [somebibtex][tugboat.bib]
\registerbibtexfile  [somebibtex][test.bib]
% \registerbibtexentry [somebibtex][Hagen:TB26-2-152]
\preparebibtexsession[somebibtex]
\applytobibtexsession[somebibtex][bibtex]

\xmlsetup{bibtex:somebibtex}{xml:bibtex:sorter}

\stoptext

