Forum Moderators: open
My problem is that the forms will need to contain a lot of dynamic content (Such as parts of the form being hidden or shown depending on which options the user chooses and so on) so I was wondering if it is possible to tackle this with php and XML/XSL? Is there anyway easy way to use javascript on an XML generated webpage.
One example is that the form will consist of different pages with next and previous button to go through every page (Until the user reaches the last one and submits).
Best Regards
NooK
You can always insert JavaScript into XSLT with CDATA sections (I do this as well).
I hope this helps.
The only time I recommend client-side XSLT is when you're giving the user XML as a web service (eg. an API, RSS feed, et al), and you want to pretty it up when someone looks at it in a browser that supports client-side XSL. A lot of RSS feeds are rendered nicely this way. But it's unfriendly to send XML to someone when HTML is more appropriate, relying on their browser to turn it into a readable, useable interface.
Imagine if you're one of those poor suckers who tries to fill out your form using a hand-held device, WebTV in their hotel room, or something similar. They'll see a readout of confounding XML, not the dynamic interface you intended.
Design your forms as though they're regular XHTML. Use Javascript to do your fancy effects - hiding and showing parts of the form. Be aware that some % of your users will not have Javascript enabled, and won't "get" your show+hide effects... will you care? Put your JS in an external file and call it in the <head>. Then use XSLT to create a faithful rendering of that HTML form, of course using the data in your XML source to customize the fields or whatever.
Rendering HTML with server-side XSLT is pretty similar to rendering it with PHP or ASP or what have you - your end goal is to have some nice valid (x)HTML sent to the client. The method you use to render that HTML is a personal choice.
Rule of thumb (admittedly a thumb which I sometimes break):
* If the data you're rendering is transported as record columns in a table or array, build your HTML using for-loops and variables and typical programming methods. Forcing things through an XML->XSLT layer adds often unnecessary overhead.
* If the data you're rendering is transported as XML, toss it through an XSLT transformation and rejoice in its elegance.