我有一个自定义函数说<?php this_content('Main heading'); ?>
,我想在我的xsl里面添加,看起来像这样:
<xsl:template match="page" mode="body">
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
我已经设置了registerPHPFunctions(),但这仅适用于php内部函数..?
不,它适用于您定义的功能.确保已将php命名空间添加到打开的XSL标记中,如下所示:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl">
Run Code Online (Sandbox Code Playgroud)
然后你可以使用调用你的PHP函数php:function('function_name', ...)
.
(您不能像在.php文件中那样嵌入PHP代码块.)
有关详细信息,请参阅有关registerPHPFunctions()的PHP手册页的示例和注释.