%D \module
%D   [       file=publ-xml,
%D        version=2013.12.24,
%D          title=\CONTEXT\ Publication Support,
%D       subtitle=XML,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Publication Support / XML}

\unprotect

\unexpanded\def\convertbtxdatasettoxml
  {\dosingleempty\publ_convert_to_xml}

\def\publ_convert_to_xml[#1]%
  {\clf_convertbtxdatasettoxml{\iffirstargument#1\else\s!default\fi}} % or current when not empty

% \startxmlsetups btx:initialize
%     \xmlregistereddocumentsetups{#1}{}
%     \xmlsetsetup{#1}{bibtex|entry|field}{btx:*}
%     \xmlmain{#1}
% \stopxmlsetups

\startxmlsetups btx:initialize
    \xmlsetsetup{#1}{bibtex|entry|field}{btx:*}
    \xmlmain{#1}
\stopxmlsetups

% \startxmlsetups btx:entry
%     \xmlflush{#1}
% \stopxmlsetups

\startxmlsetups btx:field
    \xmlflushcontext{#1}
\stopxmlsetups

\protect \endinput

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

% \startbuffer
% \startxmlsetups xml:bibtex:sorter
%     \xmlresetsorter{bibtex}
%   % \xmlfilter{#1}{entry/command(bibtex:entry:getkeys)}
%     \xmlfilter{#1}{
%         bibtex
%         /entry[@category='article']
%         /field[@name='author' and find(text(),'Knuth')]
%         /../command(bibtex:entry:getkeys)}
%     \xmlsortentries{bibtex}
%     \xmlflushsorter{bibtex}{bibtex:entry:flush}
% \stopxmlsetups
% \stopbuffer

% \bgroup
%     \setups[bibtex-commands]
%     \getbuffer
% \egroup

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

% \startpacked
% \getbuffer
% \stoppacked


% \unexpanded\def\btx_xml_list_handle_entry
%   {\begingroup
%    \ignorespaces
%    \xmlfilter{btx:\currentbtxrendering}{/bibtex/entry[@tag='\currentbtxtag']/command(btx:format)}%
%    \removeunwantedspaces
%    \endgroup}

% \startxmlsetups btx:format
%     \btxlistparameter\c!before\relax % prevents lookahead
%     \edef\currentbibxmlnode {#1}
%     \edef\currentbibxmltag  {\xmlatt{#1}{tag}}
%     \edef\currentbtxcategory{\xmlatt{#1}{category}}
%     \ignorespaces
%     \xmlcommand{#1}{.}{btx:\currentbtxformat:\currentbibxmlcategory}
%     \removeunwantedspaces
%     \btxlistparameter\c!after\relax % prevents lookahead
% \stopxmlsetups

% \startxmlsetups btx:list
%     \xmlfilter{#1}{/bibtex/entry/command(bibtex:format)}
% \stopxmlsetups

% \startxmlsetups btx:btx
%     \xmlfilter{#1}{/entry/command(btx:format)}
% \stopxmlsetups

% \unexpanded\def\btx_xml_doifelse#1{\xmldoifelse\currentbibxmlnode{/field[@name='#1']}}
% \unexpanded\def\btx_xml_doif    #1{\xmldoif    \currentbibxmlnode{/field[@name='#1']}}
% \unexpanded\def\btx_xml_doifnot #1{\xmldoifnot \currentbibxmlnode{/field[@name='#1']}}
%            \def\btx_xml_flush   #1{\xmlcontext \currentbibxmlnode{/field[@name='#1']}}
%            \def\btx_xml_setup     {\xmlsetup   \currentbibxmlnode} % {#1}
% \unexpanded\def\btx_xml_todo    #1{[#1]}

% \xmlfilter{#1}{/field[@name='\currentbtxfield']/btxconcat('\currentbtxfield')}
