Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to include script tag in an xsl file?

Tags:

xslt

I'm working on an old site that uses java and xsl. How can I inculde a script file in an xsl file? Top of the file:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:include href="shipmentPackageInfo.xsl"/>

<script src="/fs/scripts/shipment/shipment.js"></script>

breaks the app

-- UPDATE --

There is another file called pageHeader.xsl which has all the script tags inside of

<xsl:output method="html"/>
  <xsl:template match="PageHeaderData">
like image 440
Mark Steggles Avatar asked Dec 23 '11 00:12

Mark Steggles


3 Answers

Oh, I do like this:

... ...
        </body>
<script language="javascript"><![CDATA[
var a_patch = function(){
    var links = document.getElementsByTagName("a");
    for (var i=0; i<links.length; i++){
        var link = links[i];
        var text = link.innerHTML;
        ... ...
    }
};
a_patch();
]]></script>
</html>
like image 64
thinkbase Avatar answered Oct 03 '22 04:10

thinkbase


Take a look at my answer to XSLT wont allow me to use self-closing img and br tags

Self closing script tags (<script src="code.js"/>) can cause the JavaScript files not to load, so inside of your XSLT, you may need to have some text inside the script tag to keep it from self closing and get it to work.

<script src="code.js>//</script>
like image 10
Kevin Hakanson Avatar answered Oct 23 '22 08:10

Kevin Hakanson


There seems to be a solution here:

http://www.webdeveloper.com/forum/archive/index.php/t-20815.html

Put javascript code between <xsl:text> tag something like below

<script type="text/javascript">

<xsl:text>

javascript here

</xsl:text>

</script>
like image 9
annonymously Avatar answered Oct 23 '22 07:10

annonymously