Shalini
Shalini

Reputation: 348

How to fetch document directory from the document URI in MarkLogic?

I am having a list of URI's with different directories. Is it a way to fetch all the distinct directory from the URI's in MarkLogic ?

xdmp:directory is used for different purpose.

Example- 
let $uri := "/test/abc/somepath/abc.xml"
Output should be- "/test/abc/somepath/"

Any Suggestions ??

Upvotes: 1

Views: 164

Answers (2)

mholstege
mholstege

Reputation: 4912

There is a utility function that does this:

import module namespace util="http://marklogic.com/xdmp/utilities" at "/MarkLogic/utilities.xqy";
util:basepath("/test/abc/somepath/abc.xml")

It uses fn:replace plus a little logic around edge cases.

Upvotes: 6

wst
wst

Reputation: 11771

There's no built-in function for this, but you can parse out the directory value from a URI a couple different ways, depending on how strict you want to be.

fn:string-join(fn:tokenize('/test/abc/somepath/abc.xml', '/')[1 to last()-1], '/')||'/'

Or if you only want to match when the string leads with a /:

replace('/test/abc/somepath/abc.xml', '^((/[^/]+)*/)[^/]*$', '$1')

Upvotes: 4

Related Questions