PHP in XSLT. PHP Example

php-in-xslt.php:
<?php
function fooString($id ) {
    
$ret  'fooString: Input parameter is of type: ' ;
    
$ret .= gettype($id) ."\n";
    
$ret .= ' and has the value ' $id;
    return 
$ret;
}
function 
fooNode($node ) {
    
$ret  'fooNode: Input parameter is of type: ';
    
$ret .= gettype($node) ."\n";
    
$ret .= '  There are 'count($node) . ' nodes. ';
    
$ret .= 'The first one has the value: ' $node[0]->value;
    return 
$ret;
}  
function 
nodeSet() {
    
$dom = new domdocument();
    
$dom->loadXML("<root>this is from an external DomDocument</root>");
    return 
$dom;
}
$xsl DomDocument::load("examples/php-in-xslt.xsl");   
$xml DomDocument::load("examples/books.xml"); 
$proc = new xsltprocessor();
$proc->importStylesheet($xsl);
$proc->registerPhpFunctions();
print 
$proc->transformToXml($xml) ;
 
PHP in XSLT. PHP Example © copyright 2004  Bitflux GmbH