PDA

View Full Version : Running Javascript from XSL


ronron5477
03-25-2010, 03:03 PM
Ok, so I have an XSL and i would like to the Javascript with in it.
I have something like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:xalan="http://xml.apache.org/xslt">
<xsl:output method="html"/>


<xsl:template >
<script language="javascript" grp="xsljs">
myarr[myarr.length]="1234";alert("hey there");
</script>
</xsl:template>
</xsl:stylesheet>

The Javascript won't run once it prepares the html code.
I have to do a document.getElementsByTagName("script") once the xsl has ran, find the scripts with the tag "grp" equal to the "xsljs", then run an eval on the script's innerHTML to kick it off.

Is there any other way to do this? Is there any way to run the javascript in the XSL?

drhowarddrfine
03-25-2010, 03:29 PM
The 'language' attribute was deprecated years ago in HTML. You should use 'type="text/javascript"'
You need to set the HTML namespace. xmlns="http://www.w3.org/1999/xhtml"

Dormilich
03-25-2010, 04:22 PM
You need to set the HTML namespace. xmlns="http://www.w3.org/1999/xhtml"

Doc, that’s XHTML, not HTML (as requested). In this case it might be better to output XHTML rather than HTML. further, any CSS and JavaScript code in XSL should be written as CDATA, otherwise you’ll be thrown off with an error at the next <, > or & (etc.).

PS. grp is not a valid attribute for <script>