Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework And XML/XSLT Integration

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">

    <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"/>

    <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.

like image 952
Richard Knop Avatar asked Dec 12 '09 21:12

Richard Knop


1 Answers

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)

like image 97
Bill Karwin Avatar answered Sep 24 '22 23:09

Bill Karwin