簡體   English   中英

如何在xslt中包含javascript文件和來自文件的調用函數?

[英]How to include javascript file and call function from file in xslt?

我正在嘗試調用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>

XSL-JS.xsl,我聲明過js文件的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:templatename="headers">
<scriptsrc="KS.js"type="text/javascript">&#160;</script>
</xsl:template>
</xsl:stylesheet>

定義功能的KS.js javascript文件

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

輸出帶有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錯誤圖片 在此處輸入圖片說明

山姆嘗試這樣做:

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

將其重命名為所需名稱,然后將其放入測試文件夾中-看看是否可行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM