saxonexist-db

Can Saxon XSLT save XML to eXist-db?


Can Saxon XSLT save XML to eXist-db? I've searched documentation and forums, but could not find anything explicitly documented. I can read from eXist-db with doc('http://localhost:8080/exist/rest/db/winequest/mysave.xql'), but don't see an explicit way to write XML. I've tried this, but it silently doesn't execute mysave.xql.

<xsl:result-document href="http://localhost:8080/exist/rest/db/mysave.xql">
    <xsl:sequence select="$node"/>
</xsl:result-document>

I'm guessing Saxon doesn't see http: as a viable result-document destination, i.e. via a POST. Or to put it another way, I'm looking to send an http POST of XML content to Xquery on eXist-db, so it can store that XML. I can probably alternatively URL encode a little XML using doc($url), but that will quickly run into limits.

So what is the preferred mechanism for Saxon XSLT to save XML to eXist-db?


Solution

  • When you invoke Saxon from Java you can call Xslt30Transformer.setResultDocumentHandler(...) to supply a callback function which will be invoked to handle the output of xsl:result-document instructions. The callback function is supplied with a URI, and returns a Destination which Saxon will write to. The Destination can be anything you like; you can implement the logic here to write the result document to an eXist database.