I wonder (as I couldn't find anything either on DaniWeb or anywhere else) why should one use XML and XSLT rather than plain XHTML?

I couldn't find a rationale arguing for the use of XML and XSLT in connection with dynamic web content stored in a database.

Zend does provide a tutorial for "Using PHP and XSL to Transform XML into Web Content" but no reason of why should anyone want to use this combination.

I can guess reasons pro but I'd like to know why shouldn't it be used to create web content.

My reason for the use is that XML and XSLT furthers the separation of plain content (data) from style (XSLT and CSS) thus makes maintenance easier.

Please, argue pro and contra as a simple "anything has its advantages and weaknesses" (an answer I found here on DaniWeb regarding a similar question) are self-evident and not helpful.

Recommended Answers

All 13 Replies

Pro: If you can retrieve your (database, rss) data in XML then with XSLT you can easily turn it into an (X)HTML page.

Example: If you want to show part of an external RSS feed on your website, then with XSLT it can easily be transformed into a structure that fits your website. The XSLT can easily be changed, without the need of changing your code.

Con: Often slower than other solutions. 'Old-fashioned' solution to some. Other newer options are often available to achieve the same.

My $0.02

Thanks, pritaeas!

What other, newer options are there and what are their respectives advantages and weaknesses? The speed may not be the as important for my upcoming project (creating a modern website with integrated management tools for its content and full accessibility for visually challenged people).

For me, I've learned XSLT when switching to ASP.NET. The newer option here would be repeaters. There are probably more newer options, also for different languages, but I'm not using them at the moment, so it would be an uninformed guess.

What language are you using for your project ? Maybe that can trigger an additional response ;)

I have PHP (with XML and XSLT) and MySQL at my disposal (so ASP is out of question).

I know that I could create this page simply with PHP and MySQL building XHTML pages, but I was looking for alternatives that does make sense (and will be interesting to learn, as this project is primarily meant for training with the objective that it can be actually used as well - sort of an internship or workplace training).

If it is for training, then there is no reason not to try XSLT.

I don't know where you get your XML from. My sites are normally built by getting MySQL data into an array/object and passing it to Smarty (PHP template system). That also takes cares of caching.

Basically I wanted to try to develop a CMS (like Typo3) for this website in a much simplified form. So, the text will be written on the website and stored in a MySQL database, and then I have to figure out the rest.

So far in my training we have just covered the basics of .NET programming (C# with Visual Studio 2008), creating a database (SQL Server 2008) and a bit of PHP for MySQL.

I'll start this project next monday and the first thing I'll do is figuring out which technology/languages to use.

Thanks, I'll try that next week when I'm home. (Here in the training center the internet is frequently disrupted and a lot of webpages are blocked.)

I'll also check the source code of some CMS as well as XML languages like SRGS, SSML and PLS...

Still, I wonder how to procede to achieve my goal: administration panel => database => XML? And of course: XML + XSLT + CSS => web browser?

Any advice is welcome!

I will look into it for myself (but maybe not on my own - thank DaniWeb), but it looks like you need to have control over the server (in order to install the lib_mysqludf_xql library), but the website I have to create will be hosted on a free webhosting service in France (Free.fr) where I have no control over the server or either packages (PHP or MySQL among possibly others - I haven't got access yet).

How to get the content from the administration panel into the database seems obvious (SQL queries like INSERT etc.) but I haven't got yet an idea how to create the XML files. (Or I might skip the MySQL part and store everything right away in XML files, but for one - I don't know whether the result will still count as a database and I'm kinda obliged to create one while for training purposes, and two - I'm not sure whether this is actually better. What is the combination PHP+XML usually used for?)

And try as I may I can not find an answer to my initial, later rephrased question:

Why would anyone use XML with XSLT in combination with PHP?

Obviously PHP would allow similar functionality as XSLT (Bruno Pedro wrote that using PHP allows for better flexibility while XSLT is supposedly easier). Is there any reason (my training aside) to try and use PHP+MySQL with XML+XSLT? (And could you try to explain your response?)

Thank you!

If it is not for training, then I wouldn't recommend using PHP/MySQL with XML/XSLT. The main reason would be that MySQL has no built-in support yet to return result sets as XML (like MSSQL has). So, if you would use XML/XSLT that means you need to extract data, convert it to XML and then parse it with an XSLT. You'd be better of to get the data, and use a PHP template system to build your output.

Okay, thanks. I'll do it the simpler (?!) way using PHP to access MySQL and create XHTML.

Thanks a lot. I'll mark this thread as solved, though I still would like to know when would anyone use PHP with XML!?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.