Вы можете использовать токены для получения каталогов, а затем использовать рекурсивную функцию для вычисления желаемого результата.Примерно так (проверено на try.zorba-xquery.com):
declare function local:compute-relative-uri($absolute as xs:string,
$current as xs:string)
{
local:compute-relative-uri-aux(tokenize($absolute, "/"),
tokenize($current, "/"))
};
declare function local:compute-relative-uri-aux($absolute as xs:string*,
$current as xs:string*)
{
if (head($absolute) eq head($current))
then
local:compute-relative-uri-aux(tail($absolute), tail($current))
else
let $steps := (for $dir in 1 to count($current) - 1 return "..", $absolute)
return string-join($steps, "/")
};
let $absolute := "file:/folder1/file2.txt"
let $current := "file:/folder1/folder2/file1.txt"
return
local:compute-relative-uri($absolute, $current)