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:
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With