duanbimo7212 2012-04-05 16:48
浏览 36

有没有人从PHP模板到XSLT模板而不后悔呢?

There is a certain framework I'm using in which the main developers are considering drastically changing from native PHP based templating to XSLT templating.

I'm worried that this won't be feasible because on our sites we usually have very complex templating logic.

For something as simple as this:

    if ( $something ) { ?>
        <p><?php if ( $another ) { ?>Lorem Ipsum<?php } else { ?>Dolor amet<?php } ?>.</p>
    <?php } else { ?>
        <p><?php if ( $another ) { ?>Lorem Ipsum<?php } else { ?>Dolor amet<?php } ?>.</p>
    <?php } ?>

The equivalent XSLT would be:

    <xsl:choose>
        <xsl:when test="blah">
            <xsl:choose>
                <xsl:when test="another">
                    <p>Lorem Ipsum.</p>
                </xsl:when>
                <xsl:otherwise>
                    <p>Dolor amet.</p>
                </xsl:otherwise>
        </xsl:when>
        <xsl:otherwise>
                <xsl:when test="another">
                    <p>Lorem Ipsum.</p>
                </xsl:when>
                <xsl:otherwise>
                    <p>Dolor amet.</p>
                </xsl:otherwise>
        </xsl:otherwise>
    </xsl:choose>

With such a simple code snippet, it scares me when I think of advanced scenarios.

I'm wondering if anyone has undergone through a similar templating conversion and if so, how did you cope with it? Did you go back?

  • 写回答

2条回答 默认 最新

  • donglengyuan6826 2012-04-05 16:54
    关注

    In my experience, eventually, I always go back to plain .phtml files - not that this is the right thing or the ideal thing, but what solved the problems at the time.

    XSLT never got things right for me, even for simpler logic templates.

    If there is any template system that has made me happy, that was Twig.

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能