Re: [xsl] &

Subject: Re: [xsl] &
From: Abel Braaksma <>
Date: Wed, 21 Mar 2007 12:33:22 +0100
Marco wrote:

<A onmouseout="cs()" href="{./@url}"><xsl:attribute name="onmouseover"><xsl:text>return ss('visit </xsl:text><xsl:value-of select="./@visible_url" disable-output-escaping="yes" /><xsl:text>')</xsl:text></xsl:attribute>TITLE</A><br />
<font size="-1"><span class="test">BODY</span><br />
<a HREF="{./@url}"><font size="-1"><xsl:value-of select="./@visible_url" disable-output-escaping="yes"/></font></a>

the problem is the onmouseover attribute where I get:

url2?escape&amp;amp;chars and in my page I see url2?escape&amp;chars

You are making it much harder than you need to. Do not use onmouseover just to display a text, use the attribute 'title', which works on all modern browsers and does the escaping automatically.

Further, you are mixing your problem a bit, it is not XSLT, but js scripting that contains your problem. You show us your HTML (one advice: please use only lower-case for attribute and element names in HTML, that way you are prepared for XHTML) from within XSLT, but what we need is the output from the processor.

The problem is not in your disable-output-escaping, but in the way that browser escape, render and display your data. What is inside the <a>...</a> is automatically resolved, hence any &amp; will become &. But what's in your javascript depends on how you deal with it. I'm not sure of the JS function, but I guess you want something like value.unescape(). But then again, this can likely be achieved with a simple title attribute.

Furthermore, if you do stick to the onmouseover with a javascript call, using the same text as already in the a-href element, use the popular (but often discouraged) syntax of your_function(this), which gives you all control you need. You will see that if you use, in your script, obj.href or obj.firstChild.value that you will still see the unescaped value of your @visible url.

Last but not least: you do not need to prefix your XPath expressions with ' ./ ', you can safely remove that. But of course, that's all a matter of taste.

-- Abel Braaksma

Current Thread