[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Get Document File name


Subject: Re: [xsl] Get Document File name
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Mon, 23 Oct 2006 08:35:32 +0200

Frank Marent wrote:
hi phil

Is there a way to get the file name of the document you are processing? If I
use Document-uri() it returns the whole file path.

i'm using


tokenize(document-uri(/), '/')[last()]

or '\' if working with backslashes.

A backslash cannot be a literal part of a URI, it is not allowed. It must be escaped for that purpose as %5C. Because a URI may well have additional information after the 'filename', namely the query part and the fragment part, I recommend using the regular expression that is provided as a convenience in the RFC2396 paper. It puts the path in $5::


^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
12            3  4          5       6  7        8 9

You can use the tokenize function above for splitting $5. Not however that that a path separator not necessarily be a slash, it depends on the scheme part ($2) what is and what is not allowed in the path expression.

Cheers,

-- Abel Braaksma
  http://www.nuntia.com


Current Thread