本文介绍了XSLT 模板中的常规 PHP 代码,可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以以及如何在我的 XSLT 模板中包含代码...我知道我可以使用 <xsl:choose> 但这不能满足我的需求,我想要添加函数、变量等...

I wonder If I can and how can I include code inside my XSLT template... I know I can use <xsl:choose> but that doesn't satisfy my needs, I want to add functions, variables etc...

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:php="http://php.net/xsl"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" encoding="UTF-8" indent="yes"/>

<xsl:template match="BackgroundReportPackage">

<!--- here i would like to add code like ---->

if ($dateofcharge < 7) {
return '

<xsl:for-each select="Charge">
            <table class="special2" cellpadding="0">
                <tr class="tr-border-bottom">
                    <td class="front-td-text" valign="top">Charge ID: </td>
                    <td class="minimalec">
                    <xsl:value-of select="ChargeId"/>
                    </td>
                </tr>

                <tr class="tr-border-bottom">
                    <td class="front-td-text" valign="top">Charge Type Classification: </td>
                    <td class="minimalec">
                    <xsl:value-of select="ChargeTypeClassification"/>
                    </td>
                </tr>

            </table>

';
} else {
 do nothing
 }

 <!--- keep in mind that this code i've added is just for presentational purposes TO show you, how i want to use php code --->

</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

希望大家帮忙!

推荐答案

当 XSLT 可以执行 if 块时,没有真正的理由为什么要编写这样的模板.您可以查看的是

There is no real reason why you would write a template like that when XSLT can do if blocks. What you can look into is

更改模板值和

  • XSLTProcessor::registerPHPFunctions — Enables the ability to use PHP functions as XSLT functions

在模板中使用 PHP 函数.这可能更有意义.

to use PHP functions inside the template. This will probably make more sense.

这篇关于XSLT 模板中的常规 PHP 代码,可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 00:08