在 XSL 中定义 PHP-Function 并调用它.可能的?如何? [英] Define PHP-Function in XSL and calling it. Possible? How?

查看:39
本文介绍了在 XSL 中定义 PHP-Function 并调用它.可能的?如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如标题所说:是否可以在 XSL 文档中编写 PHP 函数并在之后调用它?

Like the title tells: Is it possible to write a PHP-Function in a XSL-Document and call it afterwards?

我没有案例,我想这样做.这是我在学习 XSL 时想到的一件事.

I have no case, where I wanna do that. Its just a thing it came into my mind while learning XSL.

在 XSL 中,您可以编写如下内容:

In XSL you can compose something like:

<xsl:processing-instruction name="php">
   ...some php...
</xsl>

PHP 代码将在您呈现的页面中运行.是否可以创建例如处理指令中的一个 PHP 函数并稍后调用它(在同一个模板中)?

The PHP code will be run in your rendered page. Is it possible to create e.g. a PHP Function in the processing-instruction and call it later (in the same template)?

伪样本:

<xsl:template>

   <xsl:processing-instruction name="php">
      ...some php processing $foo...
   </xsl>

   <xsl:variable name="foo" select="xpath/node">

   <xsl:value-of select="call-php-function-with-$foo"/>

</xsl>

我期待您的解决方案/方法:)

I'm looking forward to your solutions/approaches :)

克里斯

推荐答案

在 XSLT 1.0 中,不可能调用用另一种语言编写的函数,除非这些函数是按照特定 XSLT 的要求编写的用于扩展函数的处理器,并在启动转换时在可用扩展函数集中指定.

In XSLT 1.0 it is not possible to call functions written in another language, unless these are written following the requirements of the particular XSLT processor for extension functions and specified in the set of available extension functions at the time the transformation is to be initiated.

可以通过调用或应用模板来模拟功能.

Functions can be simulated by calling or applying templates.

在 XSLT 2.0 中,可以使用 指令.然后可以在任何其他 XSLT 指令的 select 属性中指定的任何 XPath 表达式中引用这些函数.

In XSLT 2.0 it is possible to write functions in XSLT using the <xsl:function> instruction. These functions can then be referenced in any XPath expression that is specified in the select attribute of any other XSLT instructions.

在 XSLT 1.0 和 XSLT 2.0 中甚至可以实现高阶函数 (HOF).这就是 FXSL 库(完全用 XSLT 编写)所做的.

Both in XSLT 1.0 and XSLT 2.0 it is even possible to implement higher-order functions (HOF). This is what the FXSL library (written entirely in XSLT) does.

这篇关于在 XSL 中定义 PHP-Function 并调用它.可能的?如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆