views:

664

answers:

1

Hello,

I'm trying to use XML files and XSL stylesheets instead of ordinary phtml templates in Zend Framework. I'm not sure how to implement it, though.

What I've tried to do so far:

  • instead of .phtml views I use .xsl stylesheets
  • I use .xml layouts

Here is what I do in the init() method of each controller:

$this->view->xmlStylesheet = '/../application/modules/default/views/scripts/'
. $this->_request->getControllerName() . '/'
. $this->_request->getActionName() . '.xsl';

Which gives me a path like:

/../application/modules/default/views/scripts/index/index.xsl

My layout looks like this:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="<?php echo $this->escape($this->xmlStylesheet); ?>"?>
<page>
    <header></header>
    <content></content>
    <footer></footer>
</page>

And the views look like this for example:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://www.w3.org/1999/xhtml"&gt;

    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"
     media-type="application/xhtml+xml" encoding="iso-8859-1"
     doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
     doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/&gt;

    <xsl:template match="/">
     <html>
      <head>
       <title>Hello World</title>
       <meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1"/>
      </head>
      <body>
       <xsl:apply-templates/>
      </body>
     </html>
    </xsl:template>

</xsl:stylesheet>

What I get in the browser (Firefox) though is just a blank page with source like this, for instance:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/../application/modules/default/views/scripts/index/index.xsl"?>
<page>
    <header></header>
    <content></content>
    <footer></footer>
</page>

Could somebody help me out? Take into consideration that I am an XML beginner so I'm just starting to learn how to use it effectively.

+4  A: 

Here's an article on how to create a custom Zend_View class that uses XSLT to render:

"Zend Framework: XSL and self-serializing Views" (Pascal Opitz)

Bill Karwin
Thanks. Is there some plan to include support for XSLT in official ZF release sometimes in the future?
Richard Knop
XSLT doesn't seem to be on the roadmap for ZF 2.0: http://framework.zend.com/wiki/display/ZFDEV2/Zend+Framework+2.0+Roadmap
Bill Karwin
Also I don't find any feature request related to using XSLT in Views in their issue tracker. I think most ZF users and developers would not like this feature (even though XSLT is often a lot faster to render than PHP scripts).
Bill Karwin