title: Creating remote transactions and attaching statements in MarkLogic
body: <p>I am trying to implement functionality similar to MarkLogic REST API's <code>/transactions</code> endpoint in a custom API. However, it looks like only some of the functions needed achieve this are available in XQuery. </p>
  
  <p><code>xdmp:transaction-commit()</code> and <code>xdmp:transaction-rollback()</code> are provided to remotely manage existing open transactions, but there are no corresponding XQuery functions to open a new transaction or to attach new statements to it. </p>
  
  <p>I snooped around in the REST API implementation to see how it's done there, and they use the undocumented function <code>xdmp:transaction-create()</code> with the deprecated option <code>&lt;transaction-mode&gt;update&lt;/transaction-mode&gt;</code> (I tested with the <code>&lt;update&gt;</code> and <code>&lt;commit&gt;</code> options, which segfaults the server!). </p>
  
  <p>Statements are then attached to a transaction in the XML rewriter via <code>&lt;set-transaction&gt;</code>, which doesn't correspond to an XQuery function, but I assume it's the same thing as using <code>eval</code> or <code>invoke</code> with the<code>&lt;transaction-id&gt;</code> option (also deprecated). </p>
  
  <p>A simple proof of concept using these methods seems to work fine, but I'm not sure if I'm missing a way to do this without using undocumented and deprecated features. Maybe it's okay because that's how REST API does it? It just seems odd to provide functions to commit and roll back remote transactions for which there is no approved way to create or update.</p>