将参数传递给xslt中的JavaScript脚本 [英] Passing parameters to javascript script in xslt

查看:247
本文介绍了将参数传递给xslt中的JavaScript脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在脚本位于标记< script type = text / javascript> ....< / script>之间的XSLT中处理JavaScript函数的参数。如果可能的话,有人可以举个例子。谢谢。

解决方案

我认为你在这两件事之间感到困惑:XSLT是用来产生HTML / JavaScript - 一旦生成HTML / JavaScript被浏览器接收,那么JavaScript就可以运行。我不知道任何这样的XSLT概念将一个变量传递给一个javascript函数。



我的猜测是你想要像这样的XSLT ...

p>

 < script type =text / javascript> 
var myVar =< xsl:value-of select =XPATHVALUE/>;
< xsl:text disable-output-escaping =yes><![CDATA [
function myFunc(){
alert(myVar);
}
]]>< / xsl:text>
< / script>

如果您将javascript的主体body放在xsl:text元素中,这意味着您不会被保留字符(例如<>等)捕捉到。



设置到浏览器的生成的HTML / javascript最终会成为像这样,这意味着调用myFunc将显示hello world...

 < script type =text / javascript> ; 
var myVar =hello world;
函数myFunc(){
alert(myVar);
}
< / script>

更新

<正如MichaelKey强调的那样,< xsl:text>以上元素是不必要的。这应该会产生同样的结果......

 < script type =text / javascript> 
var myVar =< xsl:value-of select =XPATHVALUE/>;
<![CDATA [
function myFunc(){
alert(myVar);
}
]]>
< / script>


Is it possible to handle a parameter to a javascript function in XSLT where the script is between tags <script type=text/javascript>....</script>. If possible could someone give a example. Thanks.

解决方案

I think you're getting confused between the two things: XSLT is something that is used (in this case) to generate HTML/javascript - once that generated HTML/javascript is received by the browser then the javascript can be run. I'm unaware of any such concept of the XSLT "passing" a variable to a javascript function.

My guess is you want something like this XSLT...

<script type="text/javascript">
  var myVar = "<xsl:value-of select="XPATHVALUE"/>";
  <xsl:text disable-output-escaping="yes"><![CDATA[
    function myFunc(){
      alert(myVar);
    }
  ]]></xsl:text>
</script>

If you put the main "body" of the javascript within the xsl:text element, it means you won't get caught out using reserved characters (such as < > etc).

The generated HTML/javascript that is set to the browser would end up as something like this, meaning calling myFunc would display "hello world"...

<script type="text/javascript">
  var myVar = "hello world";
    function myFunc(){
      alert(myVar);
    }
</script>

Update

As MichaelKey has highlighted, the <xsl:text> element above is unnecessary. This should produce the same thing...

<script type="text/javascript">
  var myVar = "<xsl:value-of select="XPATHVALUE"/>";
  <![CDATA[
    function myFunc(){
      alert(myVar);
    }
  ]]>
</script>

这篇关于将参数传递给xslt中的JavaScript脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆