开发者

XML to XHTML - Best Method?

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


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜