N. America: 800 876 3101 | World: 44 (0) 1753 218 930

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?

Submit Your DataDirect XQuery Tip or Trick

Tell us your XQuery Tip or Trick – if it gets published on our site, you’ll receive a

$10.00 Amazon.com
Gift Certificate!

Submit your tip or trick today.