0

I am trying to call javascript function that is exist in KS.js file and I have referred that file in XSLT file but it gives me javascript error, please check image below.

Could anyone suggest me where I am doing wrong?

MAIN.xsl

<?xmlversion="1.0"encoding="utf-8"?>
<xsl:stylesheetversion="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w3="http://www.w3.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:includehref="XSL-JS.xsl"/>
<xsl:templatematch="/">
<htmlxmlns="http://www.w3.org/1999/xhtml"xmlns:w3="http://www.w3.org"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<head>
<xsl:call-templatename="headers"></xsl:call-template>
</head>
<body>
<inputtype="button"value="Click"onclick="LoadSource()"style="vertical-align:middle;width:25px;height:25px;" />
</body>
</html>
</xsl:template>
</xsl:stylesheet>

XSL-JS.xsl, xsl file where I have declared js file

<?xmlversion="1.0"encoding="utf-8"?>
<xsl:stylesheetversion="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w3="http://www.w3.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:templatename="headers">
<scriptsrc="KS.js"type="text/javascript">&#160;</script>
</xsl:template>
</xsl:stylesheet>

KS.js javascript file where function is defined

function LoadSource()
{
alert('Success');
}

Output with javascript error

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:w3="http://www.w3.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<head>
<script src="KS.js" type="text/javascript" xmlns=""> </script>
</head>
<body>
<input type="button" value="Click" onclick="LoadSource()" style="vertical-align:middle;width:25px;height:25px;" />
</body>
</html>

Javascript Error Imageenter image description here

Sam
  • 433
  • 1
  • 10
  • 26
  • Is there a space between the function keyword and the name of the function, or is that just a typo? – El Kabong Jan 26 '14 at 13:49
  • @El kabong, Yes It was typo, Now, I have changed it. – Sam Jan 27 '14 at 04:40
  • @El kabong, Any clue? – Sam Jan 27 '14 at 08:48
  • 1
    Sam - I think in order to get that to work, you'll need to create a separate stylesheet to place the javascript function in, you can't use a standard js file. Have a look at this MS article for an idea of how to properly pull it off. http://support.microsoft.com/kb/273793 – El Kabong Jan 27 '14 at 12:50
  • @El, The link you have suggested describes how to use function in script, but I am expecting how to use javascript reference file in script. Please check link http://stackoverflow.com/questions/7444317/how-to-include-javascript-file-in-xslt – Sam Jan 29 '14 at 03:49
  • Sam, try just dropping the ref in the html head section - see below – El Kabong Jan 29 '14 at 15:04

1 Answers1

0

Sam try doing this:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:template match="/">
        <html>
        <head>
            <script src="KS.js" type="text/javascript"/>
        </head>
        <body>
            <input type="button" value="Click" onclick="LoadSource()"  />
        </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

Rename this to whatever you want and drop it in your test folder - see if that works.

El Kabong
  • 717
  • 1
  • 8
  • 15