1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
<?php
use TheSeer\fXSL\fXSLCallback;
use TheSeer\fXSL\fXSLTProcessor;
require 'TheSeer/fXSL/fxslcallback.php';
require 'TheSeer/fXSL/fxsltprocessor.php';
function demo() {
return 'Demo reply';
}
class foo {
public function bar($a, $b) {
$x = new \DOMDocument();
$x->loadXML('<?xml version="1.0" ?><root />');
$p = $x->createTextNode($a . ' -> ' . $b);
$x->documentElement->appendChild($p);
return $x->documentElement;
}
}
$tpl = new DOMDocument();
$tpl->load('test.xsl');
$dom = new DOMDocument();
$xsl = new fXSLTProcessor($tpl);
$xsl->registerPHPFunctions('demo');
$test = new fXSLCallback('test:only','test');
$test->setObject(new foo());
$xsl->registerCallback($test);
$result = $xsl->transformToXml($dom);
$tpl->formatOutput = true;
echo "Template:\n" . $tpl->saveXML();
echo "\n\nOutput:\n".$result;
|