Zend框架和XML/XSLT集成

Ric*_*nop 5 php xml xslt zend-framework

我正在尝试使用XML文件和XSL样式表而不是Zend Framework中的普通phtml模板.不过,我不知道如何实现它.

到目前为止我试图做的事情:

  • 而不是.phtml视图我使用.xsl样式表
  • 我使用.xml布局

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

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

这给了我一条道路:

/../application/modules/default/views/scripts/index/index.xsl
Run Code Online (Sandbox Code Playgroud)

我的布局看起来像这样:

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

并且视图看起来像这样:

<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>
Run Code Online (Sandbox Code Playgroud)

我在浏览器(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>
Run Code Online (Sandbox Code Playgroud)

有人可以帮帮我吗?考虑到我是一名XML初学者,所以我才开始学习如何有效地使用它.

Bil*_*win 6

这是一篇关于如何创建使用XSLT呈现的自定义Zend_View类的文章:

" Zend框架:XSL和自序序化视图 "(Pascal Opitz)