Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Processing custom XML namespace within XSL

Tags:

php

xslt

I'm using the php class XSLTProcessor to generate HTML from a xsl. Within the xsl, I'd like all my custom namespace elements to be processed by my own processor class.

So for example:

<xsl:for-each select="doc/elements/*">
    <doc:renderElement element="." />
</xsl:for-each>

This should call the method renderElement of an instance of my custom processor class.

I know I can enable calling php functions by using the registerPHPFunctions function. However, this only seems to support calling static methods.

like image 454
sander Avatar asked Mar 27 '26 17:03

sander


1 Answers

Yes, XSLTProcessor::registerPHPFunctions only supports static function calls of classes. However you can make use of those static calls to provide a factory or instance registry to provide actual objects. In your case probably based on the element name.

Existing code where this is done can be found in the PIWI - PHP Transformation Framework.

like image 100
hakre Avatar answered Mar 29 '26 05:03

hakre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!