Like the title tells: Is it possible to write a PHP-Function in a XSL-Document and call it afterwards?
I have no case, where I wanna do that. Its just a thing it came into my mind while learning XSL.
In XSL you can compose something like:
<xsl:processing-instruction name="php">
...some php...
</xsl>
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)?
Pseudo-Sample:
<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 🙂
Chris
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.
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 theselectattribute of any other XSLT instructions.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.