XSL Vs Views

Hello all,

I would like to know if Yii can generate XSL instead of using Views at the presentation level. We currently have an application (in native PHP) that generates an XML tree that is later rendered though it’s respective XSL in the client side. We dont want a .php file, but instead a .XSL to be rendered.

Thanks

It is very well possible to let Yii render something different than native PHP. Here is an example. It should be very well possible to render XML as well and have a matching .xsl applied.

Thanks for prompt reply Da:Sourcerer.

But I still would have to write a shorthand for XML + XSL generation.

Is there an extension to have produce something like

http://code.google.com/p/xmvc-php/

Or how would you go about it? Write own template syntax? Use one? which?

Thanks once again.

You’ll have to extend CViewRenderer in any case. I believe it were best if you’d write your templates in XSL.

You will mostly have to face two problems: Widgets and XML-serialization.

You can encounter the first one by registering wrappers for CController.beginWidget(), endWidget() and widget(). Perhaps for beginClip() and endClip() as well. You can use them within PHP’s XSLT processor via XSLTProcessor::registerPHPFunctions().

XML-serialization of models or general data is a realy heavy task. I haven’t found a good solution for this, yet. Of course you can always build your own XML document in the controllers. But that’s quite tedious. Then you could try to send flat data to your templates only. But that’s very limiting regarding flexibility. If your database model does not contain cyclic references, you can simply serialize all models including their relations. But that’s very, very costly …

So far I had a theoretical solution. But beware: I haven’t done any coding regarding this! I had the idea to look through the XSLs and scan for all <xsl:value-of> instances, analyzing what is going to be accessed by the template, cache the results and pre-load every needed relation, attribute etc. This would result into a source XML similar to this:




<?xml version="1.0" charset="utf-8"?>

<data>

  <!-- "flat" data passed as an array -->

  <flat>

    <param1>645</param1>

    <param2>asdf</param2>

  </flat>

  <models>

    <!-- serialized representation of a User model -->

    <User name="qwert" email="user@example.com">

      <!-- serialized relations -->

      <relations>

        <posts>

          <Post postid="856" message="Hello world!" />

        </posts>

      </relations>

    </User>

  </models>

</data>