1<?php 2 3class MyClass { 4 public static function dump(string $var) { 5 var_dump($var); 6 return "dump: $var"; 7 } 8} 9 10class MyXSLTProcessor extends XSLTProcessor { 11 public function registerCycle() { 12 $this->registerPhpFunctions(["cycle" => array($this, "dummy")]); 13 } 14 15 public function dummy(string $var) { 16 return "dummy: $var"; 17 } 18} 19 20function createProcessor($inputs, $class = "XSLTProcessor") { 21 $xsl = new DomDocument(); 22 $xsl->loadXML('<?xml version="1.0" encoding="iso-8859-1" ?> 23 <xsl:stylesheet version="1.0" 24 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 25 xmlns:php="http://php.net/xsl"> 26 <xsl:template match="//a">' 27 . implode('', array_map(fn($input) => '<xsl:value-of select="php:function(' . $input . ')" />', $inputs)) . 28 '</xsl:template> 29 </xsl:stylesheet>'); 30 31 $proc = new $class(); 32 $proc->importStylesheet($xsl); 33 return $proc; 34} 35