XSLTProcessor::registerPHPFunctions
(No version information available, might be only in CVS)
XSLTProcessor::registerPHPFunctions — Habilita o uso de funções do PHP como funções XSLT
Descrição
XSLTProcessor
void
registerPHPFunctions
([ mixed $restrict
] )
Este método habilita o uso de funções PHP como funções XSLT no XSL stylesheets.
Parâmetros
- restrict
-
Use este parâmetro para permite somente certas funções serem chamadas no XSLT.
Este parâmetro pode ser qualquer string (um nome de função) ou um array de funções.
Valor Retornado
Não há valor retornado.
Exemplos
Example#1 Simples chamada de função do PHP em um stylesheet
<?php
$xml = <<<EOB
<allusers>
<user>
<uid>bob</uid>
</user>
<user>
<uid>joe</uid>
</user>
</allusers>
EOB;
$xsl = <<<EOB
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="https://www.w3.org/1999/XSL/Transform"
xmlns:php="https://php.net/xsl">
<xsl:output method="html" encoding="utf-8" indent="yes"/>
<xsl:template match="allusers">
<html><body>
<h2>Users</h2>
<table>
<xsl:for-each select="user">
<tr><td>
<xsl:value-of
select="php:function('ucfirst',string(uid))"/>
</td></tr>
</xsl:for-each>
</table>
</body></html>
</xsl:template>
</xsl:stylesheet>
EOB;
$xmldoc = DOMDocument::loadXML($xml);
$xsldoc = DOMDocument::loadXML($xsl);
$proc = new XSLTProcessor();
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsldoc);
echo $proc->transformToXML($xmldoc);
?>
Histórico
Versão | Descrição |
---|---|
5.1.0 | O parâmetro restrict foi adicionado. |