This is the implementation of xmlsh   marklogic rename.  I copied this code 
from an old mailing list post so YMMV.
Copy should be the same except omit the document-delete

http://xmlsh.svn.sourceforge.net/viewvc/xmlsh/extensions/marklogic/src/org/xmlsh/marklogic/resources/rename.xquery?revision=730&view=markup




-----------------------------------------------------------------------------
David Lee
Lead Engineer
MarkLogic Corporation
[email protected]
Phone: +1 650-287-2531
Cell:  +1 812-630-7622
www.marklogic.com<http://www.marklogic.com/>

This e-mail and any accompanying attachments are confidential. The information 
is intended solely for the use of the individual to whom it is addressed. Any 
review, disclosure, copying, distribution, or use of this e-mail communication 
by others is strictly prohibited. If you are not the intended recipient, please 
notify us immediately by returning this message to the sender and delete all 
copies. Thank you for your cooperation.

From: [email protected] 
[mailto:[email protected]] On Behalf Of Jonathan Cook
Sent: Thursday, July 19, 2012 12:25 PM
To: MarkLogic Developer Discussion
Subject: [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

Reply via email to