I am trying to pass a folder path from XSL to JavaScript. Function is there in JavaScript and that function is getting called on onClick button of a HTML button in XSL. The path is like “C:\ABC\DEF\GH”. While putting an alert I saw that path is getting sent like: “CABCDEFGH”. All the slashes are removed. Even I removed the function call on OnClick event and just put an alert there with hard coded path, still same thing. It removed all the slashes.
<img class="viewcls" src="images/copy.jpg" title="Copy Profile" onclick="fnCopyProfile({$CurlDPID},'{@T}','{SOURCE/I/@DP}')"/>
Here last parameter in fnCopyProfile function’s last parameter is an XPath whose value will be a file path like C:\ABC\DEF\GH. In JS its coming without slashes.
Even if I put alert in XSL itself like:
<img class="viewcls" src="images/copy.jpg" title="Copy Profile" onclick="alert('{SOURCE/I/@DP}');fnCopyProfile({$CurlDPID},'{@T}','{SOURCE/I/@DP}')"/>
then also it is showing path without slashes.
However if I am doing this:
<xsl:value-of select="SOURCE/I/@DP" />
then it is showing path with slashes, but like this we can’t pass value into JS, I guess.
How to send the exact path with slashes to JavaScript.
Thanks in advance.
Make sure you are escaping all
\characters. When used in a JavaScript string,\is used to denote a control character (e.g.\nfor a newline).So what you need to do is replace all
\characters with\\.I do not know how you would do that with the inline variables you’re using (hopefully Dimitre will show us).
However, you could do it like this…UPDATE
The above cannot work, as
translateworks by replacing a single character with a single character.If you are using XSLT 2.0, then I believe you can do this (w3.org reference)…
The reason for the
\\is that the 2nd and 3rd parameters are regular expressions, so need the\escaping.If you are using XSLT 1.0, then I have just found this post via Google which provides a “search and replace” template
Which you should be able to call like this (I have put it into a variable to make it clearer)…