mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 08:58:56 +00:00
Add an example here
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@207796 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
aa9426e7c0
commit
7166c90417
1 changed files with 49 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.5 $ -->
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<refentry id="function.xsl-xsltprocessor-register-php-functions">
|
||||
<refnamediv>
|
||||
<refname>XSLTProcessor->registerPHPFunctions()</refname>
|
||||
|
@ -46,6 +46,54 @@
|
|||
&return.void;
|
||||
</para>
|
||||
</refsect1>
|
||||
<refsect1 role="examples">
|
||||
&reftitle.examples;
|
||||
<para>
|
||||
<example>
|
||||
<title>Simple PHP Function call from a stylesheet</title>
|
||||
<programlisting role="php"><![CDATA[<?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);
|
||||
?>]]></programlisting>
|
||||
</example>
|
||||
</para>
|
||||
</refsect1>
|
||||
<refsect1 role="changelog">
|
||||
&reftitle.changelog;
|
||||
<para>
|
||||
|
|
Loading…
Reference in a new issue