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]
<body>
<p><span class="caption">Caption 1 <a data-type="tbl" name="lbl-1"/></span></p>
<table>table 1 with caption</table>
<table>table 2 without caption</table>
<p><span class="caption">Caption 3 <a data-type="tbl" name="lbl-2"/></span></p>
<table>table 3 with caption</table>
</body>
\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