I just learn of ways to use XML data file and XSLT to create a webpage (transform from XML to HTML or XHTML). But I have never seen a webpage that has the source code of XML with a link to an XSLT file. Is it not a good solution?
You’ll have to do the conversion on the server, because not every browser supports XSLT.
Sure there's pages that are generated using XSL+XML, but I bet most of them are parsed server-side, not clientside. Then, if you open an aspx or php page, you can't really tell whether or not it's been parsed from XML and XSL files.
It's quite a decent template mechanism, too. We use it for web pages at our firm, as well as e-mail and some other media. That would be the advantage of XML in this regard; it's not media aware and you can transform your source xml into many formats (most of which will be xml-based).
There is a sample PHP Application using XML/XSLT to generate HTML, with server- and client-side demos at Tony Marston's A Sample PHP Application, with plenty of reasoning, howtos and such.
Blizzard's world of warcraft websites and their armory website have the only website I've ever seen that sends xml and uses client side xslt to display it. It seems to work quite well and they are pretty high volume sites. (Be aware that it looks at the user agent and does the transformation server side for some browsers, I know it does it client side for IE)
If you already have the data as XML (or its easy to turn it into XML) then I'd say it's a good solution. You probably want to make sure that your web server is configured properly to ensure that the XSLT is getting cached on the client side so that it doesn't have to do the request every time.
If the data isn't in XML already, there are better templating solutions out there (PHP, JSP, ASP, etc.) that are better suited to whatever environment you're in.
It's a good solution if it fits your needs. A client side XSLT transformation is ...
... good because:
- you can use templates on cheap netspace without any server support
- very good for heavy traffic
- the site works even offline on CD/DVD/USB-Stick
- header, footer, navigation etc. is in the XSLT script and loaded only one time, good for speed with many similar pages.
... bad because:
- Some niche browsers may not support XSLT
- you will not be present at google, the XML file ist not appropriate for serch engine spider
I do not think it is a good architecture for public-facing web sites:
- Although most browsers will support client side XSLT, not all will
- Even if they do, there may be individual browser compatibility issues as with javascript
- Being able to 'view source' is an incredibly useful tool for debugging. You can't do this with XSL
- Google supposedly will rank well marked up HTML higher than XML documents
- XSL is a horrible language
- You still need to render to XML (unless your data is natively XML), so why not render directly to (X)HTML?
If your data is natively XML, then it might make sense to convert it via XSL on the server side (I have written systems that do this), but that is the only situation and architecture I would use XSL in building a web site.