tags:

views:

77

answers:

3

Not wishing to be subjective but I have a need to get data from an XML source and convert it to (X)HTML. From my understanding I can do this with PHP (or other server-side scripts), Javascript, or XSLT. My feeling is that it would be more appropriate to use XSLT as it is dealing with an XML source and this is the purpose for which XSLT exists. I also see it having the advantage that it will still work if the user doesn't have Javascript enabled and wont be restricted to a server which runs PHP (or other server-side script). Am I right in my assumptions?

Also could the same be same for an RSS feed?

Thanks

+2  A: 

Yes, XSLT is probably a good bet for this. It should be able to run without JavaScript (in modern browsers, but I think even IE 6 supports this) and PHP. Since RSS (if valid!) is just a form of XML, using this as your source should work just fine.

djc
Excellent. The RSS source is valid as far as I know but I'll double check.
Ian
+5  A: 

This depends on how radical your transformation should be.

XSLT is genuinely good at transforming existing data from a source format to a target format. It is genuinely bad at calculating or looking up and integrating additional data (e.g. database lookups, string processing, etc). If you expect to need the latter, XSLT is not the best tool.

In any case, I would try to do my processing on the server. Formatting data on the client is nice but heavily depends on the existence of client capabilities. You cannot always predict these.

For example, transforming RSS to (X)HTML is very easy with XSLT, and there is no need to off-load this task to the client. If you would use, say, PHP to do it instead, your server would do all the work anyway. Just because some clients can run XSLT that's no reason (at least for me) to let clients control the page rendering.

Tomalak
Some interesting points. The transformation in this particular case is actually a very straight forward one with no need for data calculations or lookups. So you would recommend PHP over XSLT even for a simple transformation of say an RSS or raw XML source? Surely this would make XSLT redundant?
Ian
@Ian: Not at all! I thought my answer made it quite clear that XSLT is the perfect tool for a straight-forward transformation… Where exactly do you read that I think PHP should be used even for simple jobs?
Tomalak
Sorry Tomalak, my mistake. Looks like I read your post a little too quickly :P. I'm glad that it's a clean sweep on XSLT recommendations. I've not had to use it before but I really think it's quite an underestimated technology for the power and convenience it provides. Many thanks.
Ian
A: 

XSLT is the optimal way of transforming XML documents. And you're right to point out that it will give you portability, since the transformation can be handled by most browsers, by Javascript or on the server side by most programming languages. RSS is also a variant of XML, so the same reasoning applies.

nuqqsa
Thanks for backing this up. I just wanted to be sure that I wasn't overlooking something before going down one avenue or the other.
Ian