Zend框架和XML/XSLT集成

问题描述:

我想在Zend Framework中使用XML文件和XSL样式表而不是普通的phtml模板。不过,我不确定如何实现它。Zend框架和XML/XSLT集成

什么我试过到目前为止做:

  • ,而不是一个.phtml意见我使用的.xsl样式
  • 我使用的.xml布局

这是我做每个控制器的init()方法:

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

这使我喜欢的路径:

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

我的布局是这样的:

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

而且观点是这样的,例如:

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

我在浏览器(Firefox)能得到什么,虽然仅仅是一个空白页与这样的来源,例如:

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

有人可以他让我出去?考虑到我是一名XML初学者,所以我刚开始学习如何有效地使用它。

这里有一个关于如何创建一个使用XSLT来渲染一个自定义的Zend_View类的文章:

Zend Framework: XSL and self-serializing Views”(帕斯卡奥皮茨)

+0

感谢。有没有计划在将来有时在官方ZF版本中包含对XSLT的支持? – 2009-12-13 11:52:46

+0

XSLT似乎不在ZF 2.0的路线图中:http://framework.zend.com/wiki/display/ZFDEV2/Zend+Framework+2.0+Roadmap – 2009-12-13 18:19:26

+0

此外,我没有找到任何有关的功能请求在问题跟踪器中使用视图中的XSLT。我认为大多数ZF用户和开发人员不会喜欢这个功能(即使XSLT的渲染速度通常比PHP脚本快得多)。 – 2009-12-13 18:21:57

这里是一个很好的教程有几个选项来实现HTML引擎与PHPXMLXSL/XSLT

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