One of new feature of PHP5 is that the class XML/XSL parsing XSLTProcessor can now natively use PHP to perform heavy and cumbersome transformations before. Now, don't need to make a template for ucwords(), just a little bit setup and let's go!
PHP
<?php $xml = new DOMDocument(); $xml->load('flux.xml'); $xsl = new DOMDocument(); $xsl->load('flux.xsl'); $proc = new XSLTProcessor(); // On précise au parseur que l'on veut utiliser des fonctions PHP en XSL $proc->registerPHPFunctions(); $proc->importStyleSheet($xsl); echo $proc->transformToXML($xml); ?>
XSL
<!-- - Simple test pour appeler une fonction php --> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" version="1.0"> <!-- On ajoute surtout le xmlns PHP --> <xsl:output method="xml" encoding="UTF-8" indent="yes" /> <xsl:template match="root"> <html> <!-- On utilise le préfixe php pour appeler la fonction PHP native ucwords() --> <xsl:value-of select="php:function('ucwords','php peut désormais être utilisé en xsl')" /> <!-- Output: 'Php Peut Désormais Etre Utilisé En Xsl' --> <!-- On utilise le préfixe php pour appeler une méthode statique de classe --> <xsl:value-of select="php:functionString('CLASS_NAME::methodName','param_string_1',//View/param/xml)" /> </html> </xsl:template> </xsl:stylesheet>
Comment