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

6
  • Is there a space between the function keyword and the name of the function, or is that just a typo? Commented Jan 26, 2014 at 13:49
  • @El kabong, Yes It was typo, Now, I have changed it. Commented Jan 27, 2014 at 4:40
  • @El kabong, Any clue? Commented Jan 27, 2014 at 8: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. support.microsoft.com/kb/273793 Commented Jan 27, 2014 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 stackoverflow.com/questions/7444317/… Commented Jan 29, 2014 at 3:49

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.