Click to See Complete Forum and Search --> : JavaScript in XSLT


sloLearner
05-18-2009, 04:59 PM
Hi - I'm just playing with an XSL transform to turn some XML into a webpage. I'm trying to load a basic Google map API function into the page, but I just can't get it to work in FireFox (although it works fine in IE). There are no error messages in FF.


<xsl:template match="/">
<html>
<head>

<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=mykey" type="text/javascript"></script>
<script type="text/javascript">
<![CDATA[

function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
map.setUIToDefault();
}
}
]]>
</script>
</head>
etc...


Just wondering if anyone can point out what I'm doing wrong here?

Thanks!

Alain COUTHURES
05-19-2009, 05:09 AM
Did you try to look at DOM Inspector in FF to check the result of the transformation ?

sloLearner
05-19-2009, 07:33 AM
Hi - the DOM seems to simply be

HTML
HEAD
SCRIPT

and indeed the page hangs while the browser says it's transferring data from maps.google.com, so I'm guessing there's something wrong with this code (from the code before):


<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=mykey" type="text/javascript"></script>
<script type="text/javascript">

Charles
05-19-2009, 08:10 AM
If you don't already have a XSLT processor up and running get one. I prefer Xalan but Saxon is easier to set up. When I get hung up like that I like to process the XML into a file. That way I can see exactly what's going on and I can see if the trasnformed document really works.

However, in this case the problem might be that the script that you are trying to run is incompatable with XHTML (it uses document.write). Try specifying HTML output but I'm not certain that Firefox will comply. You might not be able to run this script.

sloLearner
05-20-2009, 06:19 PM
Thanks for the advice Charles - I'll investigate using an XSLT processor like Saxon to output files as it would probably make life easier. In the meantime, I guess this just isn't possible with the JS file I'm trying to use. Shame - cheers for the help though!

Charles
05-20-2009, 08:12 PM
I wouldn't give up quite yet. Not until I'm certain that Firefox won't let you output as HTML.