I'd like to capture a caption and apply it to the block-level element that
immediately follows. In the MWE, is there a more "ConTeXt way" to
accomplish the task of adding captions to tables, figures, blockquotes, etc?
% SOT
\startbuffer[demo]
Caption 1
Caption 3
\stopbuffer
\startxmlsetups xml:demo
\xmlsetsetup{\xmldocument}{*}{-}
\xmlsetsetup{\xmldocument}{a|p|body|table}{xml:*}
\xmlsetsetup{\xmldocument}{span[@class='caption']}{xml:span}
\define\CaptionText{}
\define\AnchorXref{}
\stopxmlsetups
\startxmlsetups xml:span
\define\CaptionText{\xmlflush{#1}}
\stopxmlsetups
\startxmlsetups xml:a
\define\AnchorXref{\xmlatt{#1}{data-type}-\xmlatt{#1}{name}}
\stopxmlsetups
\startxmlsetups xml:body \xmlflush{#1} \stopxmlsetups
\startxmlsetups xml:p \xmlflush{#1}\par \stopxmlsetups
\startxmlsetups xml:table
\blank
\doifelsetext{\CaptionText}{%
\startplacetable[
title={\ignorespaces\CaptionText{}\removeunwantedspaces.},
reference={\AnchorXref}
]
\define\CaptionText{}
\define\AnchorXref{}
}{
\startplacetable
}
\startembeddedxtable
\startxtablebody[body]
\startxrow
\startxcell
\xmlflush{#1}
\stopxcell
\stopxrow
\stopxtablebody
\stopembeddedxtable
\stopplacetable
\blank
\stopxmlsetups
\xmlregistersetup{xml:demo}
\starttext
\xmlprocessbuffer{demo}{demo}{}
\stoptext
% EOT