Inserting documents Hi Jon,
There is no ‘return’ after the ‘let’. Perhaps that is why it complains? Essentially, you are talking about a kind of trashcan or versioning feature. You might be able to do the same with less code (or perhaps the rename code from David is usefull), but the basic idea you have should work, without a doubt. In case you happen to be interested in versioning, then there is also the DLS library (part of MarkLogic 5.0). Note: why are you unquoting $existingSitemap? Kind regards, Geert *Van:* [email protected] [mailto: [email protected]] *Namens *Jonathan Cook *Verzonden:* donderdag 19 juli 2012 18:25 *Aan:* MarkLogic Developer Discussion *Onderwerp:* [MarkLogic Dev General] Inserting documents Hi, I wondered if there was a better way of writing the following query. Basically it is a way of copying documents. So if the document exists we want to insert the existing document into an archive location and then store the latest version and if it doesn’t exist we just store it. declare variable $documentUri := '{{docUri}}'; declare variable $documentArchiveUri := '{{docArchiveUri}}'; declare variable $*xml* as xs:string external; if (xdmp:exists(doc($documentUri))) then ( let $existingSitemap = doc($documentUri) xdmp:document-insert($documentArchiveUri, xdmp:unquote($existingSitemap), xdmp:default-permissions(), xdmp:default-collections()) xdmp:document-insert($documentUri, xdmp:unquote($*xml*), xdmp:default-permissions(), xdmp:default-collections()) ) else ( xdmp:document-insert($documentUri, xdmp:unquote($*xml*), xdmp:default-permissions(), xdmp:default-collections()) ) This query actually complains, if I take out these lines it runs ok but obviously doesn’t do what I want: let $existingSitemap = doc($documentUri) xdmp:document-insert($documentArchiveUri, xdmp:unquote($existingSitemap), xdmp:default-permissions(), xdmp:default-collections()) I wondered if there was a xdmp:document-copy type function? Thanks Jon http://www.bbc.co.uk This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated. If you have received it in error, please delete it from your system. Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately. Please note that the BBC monitors e-mails sent or received. Further communication will signify your consent to this.
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
