简体   繁体   English

通过XSL变量传递内联JavaScript函数

[英]Pass through XSL variable to inline JavaScript function

How do I pass through an xsl variable to my inline JavaScript function? 如何通过xsl变量传递给内联JavaScript函数? I want to in turn, process it and populate a table column. 我想依次处理它并填充一个表列。

  <td>
    <xsl:variable name="symbol" select="symbol"/>
    <script language="javascript">
      <![CDATA[
        $(document).ready(function () {
          getPrice('<xsl:value-of select="symbol"/>');
        });

        function getPrice(symbol)
        {
          alert(symbol);
          var target = document.getElementById(symbol + '_price');
          $( target ).html( 'test' );
        }
      ]]>
    </script>
    <div id='{symbol}_price'></div>
  </td>

If you're running this using the built-in XSLT 1.0 engine in the browser, remember that the XSLT code is simply generating HTML. 如果使用浏览器中的内置XSLT 1.0引擎运行此程序,请记住XSLT代码只是生成HTML。 Your XSLT code is generating a page that contains the source code of a Javascript function, but you can't execute this function while you are still generating the page. 您的XSLT代码正在生成一个页面,其中包含Javascript函数的源代码,但是您仍然无法在生成页面的同时执行此函数。 What you can do is to generate HTML code that calls the function, but that doesn't sound too useful in your case. 您可以做的是生成可调用该函数的HTML代码,但在您的情况下听起来不太有用。

Also, generating HTML that contains a script element inside a td element doesn't seem a very good idea. 此外,生成在td元素内包含script元素的HTML似乎不是一个好主意。

But why are you invoking Javascript at all? 但是,为什么要完全调用Javascript? As far as I can see, all your Javascript function is doing is to read the source XML. 据我所知,您的Javascript函数所做的只是读取源XML。 Surely the way to do that is with XPath expressions? 当然可以通过XPath表达式来做到这一点吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM