Use JS variable to set the src attribute for – Gavy Jun 24 '12 at 22:12

4

Are you able to use jQuery? If so you could use getScript():

http://api.jquery.com/jQuery.getScript/

$.getScript(mylink, function() {
   // do something using the JS that was loaded.
});
JonWarnerNet
  • 1,112
  • 9
  • 19
2

Try:

(function(d){
     var file = 'yourJS.js';
     var ref = d.getElementsByTagName('script')[0];
     var js = d.createElement('script');
     js.src = file;
     ref.parentNode.insertBefore(js, ref);
}(document));

What this does:

  1. Find the first script element on your page
  2. Creates a new script element with your supplied source.
  3. Then inserts that new element before the first existing script element.
Braiam
  • 1
  • 11
  • 47
  • 78
chaoskreator
  • 889
  • 1
  • 17
  • 39
0
<xsl:variable name="Path" select="/root/folder/"></xsl:variable> <!-- Global path variable. -->
<xsl:variable name="myScriptPath" select="concat($Path, 'myScript.js')"></xsl:variable> <!-- Relative script path variable. -->
<script src="{$myScriptPath}"/> <!-- Attach script. -->
Zon
  • 18,610
  • 7
  • 91
  • 99