如何在xslt中包含javascript文件和从文件调用函数?

如何在xslt中包含javascript文件和从文件调用函数?,javascript,xslt-1.0,Javascript,Xslt 1.0,我试图调用存在于KS.js文件中的javascript函数,我已经在XSLT文件中引用了该文件,但它给了我javascript错误,请检查下面的图片 有人能告诉我哪里做错了吗 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"

我试图调用存在于KS.js文件中的javascript函数,我已经在XSLT文件中引用了该文件,但它给了我javascript错误,请检查下面的图片

有人能告诉我哪里做错了吗

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>
带有javascript错误的输出

<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错误图像

Sam尝试执行以下操作:

<?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>


将其重命名为您想要的名称,并将其放入您的测试文件夹中-看看是否有效。

函数关键字和函数名称之间是否有空格,或者这只是一个输入错误?@El kabong,是的,是输入错误,现在,我已更改了它。@El kabong,有任何线索吗?Sam-我想为了让它正常工作,您需要创建一个单独的样式表来放置javascript函数,不能使用标准js文件。看看这篇MS文章,了解如何正确地完成它@El,您建议的链接描述了如何在脚本中使用函数,但我期望如何在脚本中使用javascript引用文件。请检查链接
<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>
<?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>