Forum Moderators: open

Message Too Old, No Replies

Changing xsl outside an iframe

         

rokkatar

10:17 am on May 6, 2008 (gmt 0)

10+ Year Member



Hi there,

I have an html page with an iframe within it. The iframe displays a different html page- one which displays an xml, styled with an xsl.

I want to change the xsl being used, by clicking a button in the original html (the one which houses the iframe).

Having some trouble doing so, any help would be much appreciated!

Thanks,
Rebecca

httpwebwitch

1:44 pm on May 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Rebecca! welcome to WebmasterWorld.

Changing the XSL used to display a document means it'll be rendered all over again; it's not a subtle effect like changing the background color of an element in the DOM. You're creating a spankin' new DOM. So, loading up a new XSL is really loading up a new page in the same iframe; those pages just happen to be subtly different variations of the same XML document.

You'll need to change your XSL based on something in the URL, like the querystring. Can you concoct your XML in such a way that these URLs show different XSL?

http://www.example.com/myxml.xml?xsl=style1
http://www.example.com/myxml.xml?xsl=style2
http://www.example.com/myxml.xml?xsl=style3

If you're constructing the XML using a server-side language, this should be a cinch.

hint: use a switch/case selector, on the variable $_GET['xsl']

Once you have that working, change the page inside an iframe by changing its src attribute.

<a href="#" onclick="document.getElementById('myiframe').src='myxml.xml?xsl=style2'" >reload with style 2</a>