Hi,

I am trying to get a Javascript working in an XSL document and i can't seem to make it work for some reason.

I have placed the following code within the head of my document.

<msxsl:script language="JScript" implements-prefix="user">
 <![CDATA[

function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=400,height=250,scrollbars=yes');
return false;
}  ]]>
</msxsl:script>

and am using the following code to call the javascript.

<a href="tenancyref.htm" 
   onClick="return popup(this, 'Tenancy Ref')"><img src="question-mark-icon.gif" width="20" height="20" border="0"> </a>

the doc deceleration is as follows(if it is any use)

<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">

Any help would be great fully appreciated. I am not used to xsl at all, which probably means its something simple i haven't grasped.

dave

Recommended Answers

All 2 Replies

Please check the below link.

http://msdn.microsoft.com/en-us/library/533texsx(v=vs.71).aspx

You need to change

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">

to

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts" exclude-result-prefixes="fo">

Also, use the below

<xsl:template match="documents">
 <a href="tenancyref.htm" onClick="return user:popup(this, 'Tenancy Ref')">
 <img src="alt image1.jpg" width="20" height="20" border="0"/>
 </a>
</xsl:template>

I'm not sure you need 'return' in 'onClick' attribute.

that didn't work.

My one thought is the implements-prefix="user"> is wrong in some way? How do i determine which prefix to use?

Also can the javascript be anywhere in the head or is it better to put it either above the head (ie with the includes straight under the doctype decleration) or in the body of the document itself.

Tested the javascript(and the rest of the page) on my local machine as an html document and it works fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.