RE: [xsl] Dynamically changing and running Javascript after XSL transform

Subject: RE: [xsl] Dynamically changing and running Javascript after XSL transform
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Tue, 13 May 2003 12:53:36 -0400
[Kathleen Kappers]
 
> So I run the 
> XML through an
> XSL transform to give me my new HTML, which I then stuff 
> right into the
> current HTML file.  All this works great, and saves me from 
> doing a load of
> some new HTML page, which is the ideal solution.
>  

Do you mean that you do this transformation in the browser?  Because
your description sounds like you do all the work on the server, what
with the perl scripts and all.

> The problem is I also need to dynamically change some 
> javascript.  I need to
> update some global variables that are in the original HTML 
> file, plus call a
> refresh function in the original HTML, to add the new buttons 
> into this
> button array, etc.  
>  

> My question is how do you write javascript in an XSL file and 
> get it to
> actually run, without doing a reload of the page or a load of 
> a new page?

If you really mean to do this on the browser,  could probably also use a
stylesheet to create a string containing javascript objects with the new
data you want.  Whatever call you make to to the transform would take
the return string and eval() it to insert the data into your javascript
variables.  

eval() is your friend here.  Here is a simple example you can try out -

<body>
<script type='text/javascript'>
	var str = 'alert("This is a test")'
	eval(str)
</script>
</body>

Just write a string containing the javascript you want to execute, and
let eval() do the work.

If for some reason you cannot make that work,  I would consider writing
your transform results to an invisible Iframe (it can be made invisible
by giving it a CSS style of 'display:none').  Include some javascript
that can write the desired javascript data to the parent frame and
invoke it on the Iframe's onLoad event.

This is getting pretty far OT for this list, though.

Cheers,

Tom P

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread