Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Escaping a quote

Status
Not open for further replies.

mike314

Programmer
Joined
Jun 24, 2003
Messages
143
Location
US
I've got a question, currently I am using xsl (because I'm in a stylesheet)
and I'm escaping a " character from the text. I'm then passing in that text
into a javascript function as a parameter. But when I call the function,
the replaced quotes are not present

<xsl:variable name="char">"</xsl:variable>
<xsl:variable name="replace">&ampquot;</xsl:variable>

<xsl:variable name="text" select="People/Description"/>


<a href="javascript:void(0);" onclick="javascript:caller('<xsl:value-of select="str:Replace($text, $char , $replace)"/>');


function caller(text){
alert(text);
text2 = text + "is this your description";
document.getElementById('h6').innerHTML = '<a href="javascript:void(0);" onclick="otherTime(\'' + text2 + '\'); return false;">Click here</a>'
}

even if I just pass text to the otherTime function it wont dispaly with the " charcter.
Is there a way to add it in using regexp. Not sure how to use it.

thanks
 
basically I need to go through the text variable which is being passed into caller and find a way to escape the &amp;&quot; to turn in a "

????
 
Try double escaping. You are building the string in javascript where the escapes are being interpreted and presenting the final string correctly but then that string is being sent to a javascript function where it now sees the un-escaped version of the string. Double up your escapes and on the first interpretation the first escape will be removed and the passed string will still contain the second escape.


Stamp out, eliminate and abolish redundancy!
 
>[tt]<xsl:variable name="replace">&ampquot;</xsl:variable>[/tt]
This isn't meaning much, not even well-formed and is a parse error. If you're thinking of exploding ampersand, it is this.
[tt]<xsl:variable name="replace">&amp[red];[/red]quot;</xsl:variable>[/tt]
But, it would not eventually help neither I think.

Whatever it is the [tt]str:Replace()[/tt], try this instead.
[tt]
<xsl:variable name="text">
<xsl:text>'</xsl:text>
<xsl:value-of select="People/Description"/>
<xsl:text>'</xsl:text>
</xsl:variable>
<a href="javascript:void(0);">
<xsl:attribute name="onclick">
<xsl:value-of select="concat('javascript:caller(',$text,')'" />;
</xsl:attribute>
<xsl:text>some description - why none?</xsl:text>
</a>
[/tt]
I bypass all those replace stuff which is of very doubtful value as far as I can see with what revealed which is nothing but obscurity.

In side the function caller(), do more work on your own on the innerHTML line. I do not look into it. Also, the javascript: prefix is not really necessary in most cases. But, that's off topic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top