[英]Embed Javascript file in an XSL File
我有一個xsl文件,該文件生成一個鏈接“預覽”。
<a>
<xsl:attribute name="href">
<xsl:text>#preview</xsl:text>
</xsl:attribute>
<xsl:attribute name="onclick">
<xsl:text>embeddedPreview("</xsl:text>
<xsl:text>http://docs.google.com/viewer?url=</xsl:text>
<!--Google can't reach a local development machines, so you may want to code in your production server, where Google downloads the file from-->
<!--<xsl:text>http://example.edu/</xsl:text>-->
<!-- Getting bitstreams by ID XMLUI: /xmlui/bitstream/id JSPUI: /jspui/retrieve -->
<xsl:text>/xmlui/bitstream/id/</xsl:text>
<xsl:value-of select="substring(@ID,6)"/>
<xsl:text>&embedded=true</xsl:text>
<xsl:text>");</xsl:text>
/xsl:attribute>
Preview
</a>
每當單擊鏈接時,onclick事件都會調用一個名為EmbeddedPreview的javascript函數。 EmbeddedPreview函數存儲在mylibrary.js中:
/**
* Creates an iframe with the specified source
* @REQUIRES jQuery
* @REQUIRES that there exists an element with ID preview-embed
*/
function embeddedPreview(source) {
if($("#embed").length > 0) {
//set the source to the location asked for
$("#embed").attr("http://19.46.1.34:8081/xmlui/handle/123456789", source);
} else {
//Create the embed iframe
$("#preview-embed").append("<iframe id='embed' src='"+source+"' width='100%' height='342px' style='border:none;'/>"); //requires jQuery
}
}
每當我單擊“預覽”鏈接時,就會出現一條錯誤消息:
UnCaughtReferenceError: embeddedPreview is not defined
onclick
如何在XSL文件中嵌入Javascript?
問題不在XSLT中,因為給出的錯誤指定調用了embeddedPreview
,但未找到(未定義),這意味着XSLT進行了正確的轉換。
因此,可能性是:
確保您在控制台中檢查了javascript錯誤,如果這不能解決您的問題或發現任何其他錯誤,請進行注釋。
另外,如果這不能解決問題,則可以在轉換后發布轉換后的鏈接(標簽)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.