xsl-list
[Top] [All Lists]

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

2012-07-29 07:41:59

On 29/07/2012 03:43, Lighton Phiri wrote:
I am trying to dynamically create a *nix compatible file path by
pulling information off of database tables. A number of resulting
paths have special characters that need to be escaped to be considered
valid file paths. The path below is an example of what I am dealing
with

/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/

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.


Well, disable-output-escaping certainly won't help. That's all about XML escaping (using &) and will have no effect at all on backslash-escaping.

You want something like

replace($x, '[ \n\t\r\\]', '\$0')

Michael Kay
Saxonica

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--