|
>Home>Learn XQuery> XQuery Tips and Tricks>Extracting File Names from URLs
Print
What's the easiest way to extract the file name from a URL?
Probably like this:
tokenize($uri, "/")[last()]
And if you want to replace the extension of the file name with something different, you could use this simple function:
declare function local:generate-file-name($uri as xs:string, $ext as xs:string) {
let $fileName := tokenize($uri, "/")[last()]
let $fileName := replace($fileName,'^(.*)\..*','$1')
let $fileName := concat($fileName, ".", $ext)
return $fileName
};
Next Question!
Can I instruct XQuery to not use the minimized XML tag format?
|