5

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.

2 Answers 2

6

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)

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. Is there some plan to include support for XSLT in official ZF release sometimes in the future?
XSLT doesn't seem to be on the roadmap for ZF 2.0: framework.zend.com/wiki/display/ZFDEV2/…
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).
0

Here is a good tutorial with few options to implement Html Engine with PHP, XML and XSL/XSLT:

http://www.contentwithstyle.co.uk/content/zend-framework-xsl-and-self-serializing-views/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.