Page 1 of 1

XSLTs for a better MVC model?

Posted: Wed Jul 29, 2009 1:25 pm
by Jammerious
Hi,
I am not yet too deep into my project and I am starting to like the idea of getting more and more things done with XMLs and XSLTs.
Dropping smarty ended up with my view looking quite nasty, so maybe I could do the whole thing with XML sources and XSL transformations.
I enjoy doing stuff to the tiniest of details so I actually like writing well-formed code.
So I am thinking, XSLTs must be the best way, from a respected institution, to enforce the separation of V and C.

Re: XSLTs for a better MVC model?

Posted: Wed Jul 29, 2009 1:36 pm
by alex.barylski
Or you could use a PHP alternative syntax so the widest possible audience has a clue as to whats going on. :P

XSLT looks neat, admittedly I've only read about it, never really acted on it. Tony Marston promotes the idea like the gospel, so that kind of scares me away. :lol:

I think it's the neatest when you want to easily switch your view output (client view) from XHTML to PDF, then it makes sense, as writing a PHP alternative syntax template for PDF would probalby be really disgusting.

Cheers,
Alex

Re: XSLTs for a better MVC model?

Posted: Wed Jul 29, 2009 2:35 pm
by pickle
Basically you're wanting to use XML & XSLT as a way to enforce separation of business and display logic. That can quite easily be done with just PHP - and likely with more flexibility.

Re: XSLTs for a better MVC model?

Posted: Wed Jul 29, 2009 2:41 pm
by Eran
I'd agree with Pickle, XML is very verbose and unflexible. Instead of smarty, try a more OO templating/view system, such as Savant or Zend_View. I wrote an article about the approach those systems take a while ago, which you might find relevant

Re: XSLTs for a better MVC model?

Posted: Wed Jul 29, 2009 10:09 pm
by Theory?
The thing about XML though is that its easy for systems to read. As systems become more dispersed among multiple servers, some not even local to a given cluster, the less time it takes to process any input, the better. If your application's views will need to be parsed by something other than a browser, than building an app that outputs to XML would greatly leverage your app in the long run since all it would take is a nice simple transformation to make your output readable. Otherwise, stick with what everyone else is saying.

Re: XSLTs for a better MVC model?

Posted: Thu Jul 30, 2009 4:09 am
by Jammerious
Thank you all,
taking your suggestions into account, I now plan to do something like pytrin explained in his article (nice blog, btw, I subscribed), however I'll try and make some modules with XML/XSL, like frontend news and other clearly structured parts. This would allow easy deployment of RSS sources and falls along nicely with memcached (can't wait to try this one out).

I guess I'll eventually realise what do you mean with this approach not being flexible. Other than that I don't see any arguments against XSLT. I don't know what do you mean with XML being too verbose, it's not like anyone is going to have to write any sources by hand. Each data object, if well made, can be easily represented with a XML element through a toXml() method (where the only verbosity needs to be?).

Re: XSLTs for a better MVC model?

Posted: Fri Jul 31, 2009 7:34 am
by koen.h
Another thing that may come into play is that the library for XSLT (libxslt) is installed but not enabled by default. If you would want to distrubute a project using this as open source, many people will not be able to use it.