Hi all,
I have an issue with xdmp:document-remove-collections, the way I use
this function does not work.
Here is my code explanation :
1- I want to move XML documents from one input directory to another
one (in reality, delete and recreate document)
2 - with xdmp:document-insert I add some collections to the new
document, 3 collections related to the date and one other which flags
the document as the last one ("collection-last")
3- I need to keep only one document in the collection
("collection-last") : each time I "move" a document (see 1-) I remove
all document from ("collection-last") and then I set
("collection-last") to the processed document.
But it seems that I can't remove all documents from
("collection-last"), there is no error but it does not work at all :
all document keep this collection
Help is appreciated., Thanks !
Lanz
Here is my code :
xquery version '1.0-ml';
declare function
local:clean-collection() as empty-sequence()
{
for $doc in fn:collection("collection-last")
return xdmp:document-remove-collections(fn:document-uri($doc),
("collection-last"))
};
declare function
local:document-move($targetURI as xs:string, $sourceURI as xs:string,
$myCollection as xs:string*)
as empty-sequence()
{
try {
local:clean-collection(),
xdmp:document-delete($sourceURI),
let $permissions := xdmp:document-get-permissions($sourceURI)
let $collections := $myCollection
let $quality := xdmp:document-get-quality($sourceURI)
return
xdmp:document-insert(
$targetURI,
doc($sourceURI),
if ($permissions)
then $permissions
else xdmp:default-permissions(),
if ($collections)
then $collections
else xdmp:default-collections(),
$quality ),
let $prop-ns := namespace-uri(<prop:properties/>)
let $properties := xdmp:document-properties($sourceURI)/node()
[ namespace-uri(.) ne $prop-ns ]
return xdmp:document-set-properties($targetURI, $properties)
}
catch($e) {
}
};
(:scan du repertoire d'entrée:)
for $doc in xdmp:directory("/data/items/input/")
let $sourceURI := xdmp:node-uri($doc)
let $myDate := doc($sourceURI)/Items/Item[1]/ExportDate
let $myYeardate := fn:year-from-date(xs:date($myDate))
let $targetDir := fn:concat("/data/items/repository/",$myYeardate ,"/")
let $myShortDate := fn:adjust-date-to-timezone(xs:date($myDate ), ())
let $targetURI := fn:concat($targetDir,$myShortDate,".xml")
let $myCollection := ("collection-last",
fn:concat("collection-",$myShortDate),fn:concat("collection-",fn:string-join(fn:tokenize(xs:string($myShortDate),
"-")[1 to 2],"-")),fn:concat("collection-",fn:tokenize(xs:string($myShortDate),
"-")[1]))
order by $myDate
return local:document-move($targetURI,$sourceURI,$myCollection)
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general