On Sun, 2012-07-29 at 06:30 +0200, Lighton Phiri wrote:
Yes they are allowed, but special characters need to be escaped for
one to access a file path.
[..]
phiri@PHRLIG001:~$ touch ../data/Sites/3218AD Eland\'s
Bay/Bobbejaansberg/BB15/testFile.txt
touch: cannot touch `Bay/Bobbejaansberg/BB15/testFile.txt': No such
file or directory
This is because the shell splits arguments at spaces, so you actually
gave the touch command two filenames. If you used quotes
$ touch "../data/Sites/3218AD Eland's
Bay/Bobbejaansberg/BB15/testFile.txt"
then it would work fine.
It is not necessary to escape characters from the shell inside an XSLT
stylsheet, because the shell isn't involved.
[...]
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 am getting an error when I try what you suggested.
<xsl:value-of select="{replace($filename, "[ '\\`&;]", "\\&")}" />
You don't want the curly braces there - value-of is expecting an
expression, not a string.
[...]
My file paths have special characters in them and those characters
include 'square brackets', 'parentheses', 'ampersands', etc. all of
which are interpreted differently by the regular expression given by
second argument of replace function.
That doesn't matter.
Actually what I tend to do myself is something like
replace($filename, "[^a-zA-Z0-9]+", "-")
to turn any sequence of characters other than letters or digits into a
hyphen. If it's a path rather than a filename, include / after the 9
there. But if the data is untrusted you should not normally allow /
inside it.
Finally, as Mike Kay implied in a separate message, you probably want
\$0 as the replacement, not \& (I use too many regular expression
libraries, sorry)
Liam
--
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
--~------------------------------------------------------------------
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>
--~--