0

How do I pass through an xsl variable to my inline JavaScript function? 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>

1 Answer 1

1

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. 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. What you can do is to generate HTML code that calls the function, but that doesn't sound too useful in your case.

Also, generating HTML that contains a script element inside a td element doesn't seem a very good idea.

But why are you invoking Javascript at all? As far as I can see, all your Javascript function is doing is to read the source XML. Surely the way to do that is with XPath expressions?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.