Results 1 to 2 of 2

Thread: Calling external java script function in XSLT

  1. #1
    Join Date
    Oct 2006
    San Francisco
    Ubuntu 7.04 Feisty Fawn

    Calling external java script function in XSLT


    I'm using xslt to transfer xml to html. Some of the html elements which are generated in xslt file have event handler. For example for an anchor element I have defined an onclick event handler to execute a function; however, in IE the function handler cannot be called.

    A few days ago I realized that if I write my javascript function inside the same xsl file, everything works fine, however based on my website structure, I had to use an external function to do that. Then I transfer my entire javascript file to an xsl file and included that xsl file in my main xsl file and it worked well for some of the functions.

    Since I'm using YUI, some of my javascript function use YUI APIs which are not inside any xsl document and it s not very convenient to make all yahoo library files in to an xsl element.

    Here is a few piece of code:

    The following code works fine:

    PHP Code:
    xsl:attribute name="id">
    xsl:value-of select="news_id"/>    
    xsl:attribute name="onclick">
    script language="Javascript">
    sayhi(e) {
    but if I write my sayhi function inside an external js file it won't work in IE.

    Any idea how I can call external javascript functions in my page so that i works in IE?

  2. #2
    Join Date
    Jan 2007

    Re: Calling external java script function in XSLT

    ¿That is an error?

    You cant put a <script> tag inside the onclick="" attribute. You should put it somewhere in the document, remaining valid xml.

    The HEAD section of your HTML is a good place.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts