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

Re: [xsl] Escaping special characters for *nix file path

Subject: Re: [xsl] Escaping special characters for *nix file path
From: Liam R E Quin <liam@xxxxxx>
Date: Sat, 28 Jul 2012 23:39:52 -0400

On Sun, 2012-07-29 at 04:43 +0200, Lighton Phiri wrote:

> /data/Sites/3218AD Eland's Bay/Bobbejaansberg/BB15/
> For path above to be valid in *nix, I need to escape 'spaces', 'single
> quote' with 'backslash' to get output below
> /data/Sites/3218AD\ Eland\'s\ Bay/Bobbejaansberg/BB15/

Well, spaces and quotes are allowed in Unix (and Linux) filenames, so
I'm not sure what you are doing here.

> I've been trying to play around with the 'replace' function and
> 'disable-output-escaping', but can't seem to make it work --see
> snippet below.
>  <xsl:value-of select="replace(replace(replace(replace(replace($filename,
> ' ', '\ '), '\&#40;', '\&#40;'), '&#41;', '\&#41;'), '&#91;',
> '\&#91;'), '&#93;', '\&#93;')" disable-output-escaping="yes" />

This is crazy.

replace($filename, "[ '\\`&;]", "\\&")
will probably do what you want.

Or use \s instead of space if there might be newlines.

You might also need to replace " with \"

I'm guessing you are passing the filename to a program, since you for
sure don't want to put backslashes in a path.

Also watch for filenames including things
like ../../../../../../etc/passwd :-)


Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml

Current Thread