XSL XSLTProcessor::registerPHPFunctions

(PHP 5 >= 5.0.4, PHP 7, PHP 8)

XSLTProcessor::registerPHPFunctions — PHP 함수를 XSLT 함수로 사용하는 기능 활성화


설명

public XSLTProcessor::registerPHPFunctions(array|string|null $functions = null): void

이 메서드를 사용하면 PHP 함수를 XSL 스타일시트 내에서 XSLT 함수로 사용할 수 있습니다.


매개변수

functions
XSLT에서 특정 함수만 호출하도록 허용하려면 이 매개변수를 사용하십시오.

이 매개변수는 문자열(함수 이름) 또는 함수 배열일 수 있습니다.


반환 값

값이 반환되지 않습니다.


Examples

예제 #1 스타일시트에서 간단한 PHP 함수 호출

                  
<?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="http://www.w3.org/1999/XSL/Transform"
     xmlns:php="http://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);
?>