如何在 xsl 中调用外部 javascript 函数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4526015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call external javascript function in xsl?
提问by Akshata
I have one js file in which one function is returning value.
我有一个 js 文件,其中一个函数正在返回值。
I want to compare this value with xml value in xsl file.
我想将此值与 xsl 文件中的 xml 值进行比较。
My javascript is
我的 javascript 是
function getUser()
{
return user;
}
In xsl file i want to check this value in conditon.
在 xsl 文件中,我想在条件中检查这个值。
How I can do that??
我怎么能这样??
回答by Mads Hansen
Although it is not standard, it is possible to execute JavaScript functions from within your XSLT.
尽管它不是标准的,但可以从 XSLT 中执行 JavaScript 函数。
With MSXML you can use the msxsl:scriptextension element.
通过 MSXML,您可以使用msxsl:script扩展元素。
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="http://mycompany.com/mynamespace">
<msxsl:script language="JScript" implements-prefix="user">
function getUser()
{
return user;
}
</msxsl:script>
<xsl:template match="/">
<xsl:value-of select="user:getUser(.)"/>
</xsl:template>
</xsl:stylesheet>
回答by LCJ
Refer following
参考以下
- How To Include Client-Side Script Functions in an XSL Document
- Passing parameters to javascript script in xslt
- Row value is not available in javascript
- Calling Javascript within XSL after transformation in RSS Web Part
- 如何在 XSL 文档中包含客户端脚本函数
- 将参数传递给 xslt 中的 javascript 脚本
- 行值在 javascript 中不可用
- 在 RSS Web Part 中转换后在 XSL 中调用 Javascript
Also remember to add DEFERattrinute.
还记得添加DEFER属性。
<SCRIPT LANGUAGE="javascript" DEFER="true">
<xsl:comment>
function hiLite()
{
alert("hello");
}
</xsl:comment>
</SCRIPT>

