Page 1 of 1

Help required in XSLT

Posted: Mon Jan 24, 2005 6:07 pm
by contact_naga
I am using XSLT to launch a popup from a link in my JSP page (XML data).
It works great for all the cases except for the links where the link name
contains a single quote character (something like CIELO D'AMERICA).

I have 2 java script functions which are called by the XSLT.

My code sample is as follows:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<HTML>

<SCRIPT language="JavaScript">
function openWindow(url)
{
var vesselWin = window.open (url,"newWindow","toolbar=no,width=300,height=200,scrollbars=yes,resize=yes,menubar=no");
myWin.focus();
}

function openWindow(url,param1,param2,param3)
{
url = url + '&name1='+param1+'&name2='+param2+'&code='+param3;
var myWin2 = window.open(url,"newWindow","toolbar=no,width=300,height=200,scrollbars=yes,resize=yes,menubar=no");
myWin2.focus();
}

</SCRIPT>

...........................
The above Java script functions are called as follows.

<A class="linkUnderline" >
<xsl:attribute name="HREF">javascript:openWindow('<xsl:value-of select="normalize-space(./test/infolink)"/>');</xsl:attribute>
<FONT COLOR="#000000" ><xsl:value-of disable-output-escaping='yes' select="./test/name"/></FONT>
</A>

<A class="linkUnderline" >
<xsl:attribute name="HREF">javascript:openWindow('<xsl:value-of select="normalize-space(../link)"/>','<xsl:value-of select="normalize-space(../../../test/name)"/>','<xsl:value-of select="normalize-space(../../../testname2)"/>','<xsl:value-of select="normalize-space(../../../test/code)"/>' );</xsl:attribute>
<FONT COLOR="#000000" ><xsl:value-of select="../stopdate"/></FONT>
</A>

Any help will be highly appreciated.

Thanks in advance.

Posted: Thu Jan 27, 2005 5:03 pm
by george
Hi,

I think your problem is related with the fact that you generate an invalid Javascript code. If I remember correclty you need to escape the apostrophe as \' . If your code can work if you remove the apostrophes then you can use translate to remove it, otherwise you can use a replace template to replace ' with \' . For such a template see the XSLT FAQ:
http://www.dpawson.co.uk/xsl/sect2/replace.html

Best Regards,
George

Posted: Sun Jan 30, 2005 2:51 am
by contact_naga
Thanks