|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<!-- $Revision$ --> |
| 3 | +<!-- EN-Revision: 01904e809eaf0aa60e7ce0524400ddd5681c9541 Maintainer: mumumu Status: ready --> |
| 4 | +<refentry xml:id="xsltprocessor.registerphpfunctionns" xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 5 | + <refnamediv> |
| 6 | + <refname>XSLTProcessor::registerPHPFunctionNS</refname> |
| 7 | + <refpurpose>PHP の関数を、名前空間付きの XSLT 関数として登録する</refpurpose> |
| 8 | + </refnamediv> |
| 9 | + <refsect1 role="description"> |
| 10 | + &reftitle.description; |
| 11 | + <methodsynopsis role="XSLTProcessor"> |
| 12 | + <modifier>public</modifier> <type>void</type><methodname>XSLTProcessor::registerPHPFunctionNS</methodname> |
| 13 | + <methodparam><type>string</type><parameter>namespaceURI</parameter></methodparam> |
| 14 | + <methodparam><type>string</type><parameter>name</parameter></methodparam> |
| 15 | + <methodparam><type>callable</type><parameter>callable</parameter></methodparam> |
| 16 | + </methodsynopsis> |
| 17 | + <simpara> |
| 18 | + このメソッドは、PHP の関数を名前空間付きの XSLT 関数として、 |
| 19 | + XSL スタイルシート中で使えるようにします。 |
| 20 | + </simpara> |
| 21 | + </refsect1> |
| 22 | + |
| 23 | + <refsect1 role="parameters"> |
| 24 | + &reftitle.parameters; |
| 25 | + <variablelist> |
| 26 | + <varlistentry> |
| 27 | + <term><parameter>namespaceURI</parameter></term> |
| 28 | + <listitem> |
| 29 | + <simpara> |
| 30 | + 名前空間の URI |
| 31 | + </simpara> |
| 32 | + </listitem> |
| 33 | + </varlistentry> |
| 34 | + <varlistentry> |
| 35 | + <term><parameter>name</parameter></term> |
| 36 | + <listitem> |
| 37 | + <simpara> |
| 38 | + 名前空間の中での、ローカルな関数名 |
| 39 | + </simpara> |
| 40 | + </listitem> |
| 41 | + </varlistentry> |
| 42 | + <varlistentry> |
| 43 | + <term><parameter>callable</parameter></term> |
| 44 | + <listitem> |
| 45 | + <simpara> |
| 46 | + スタイルシート中で XSL 関数が呼ばれたときにコールされる PHP の関数。 |
| 47 | + ノードリストが コールバック のパラメータとして渡された場合、 |
| 48 | + ノードリストはマッチした DOM ノードを含む配列になります。 |
| 49 | + </simpara> |
| 50 | + </listitem> |
| 51 | + </varlistentry> |
| 52 | + </variablelist> |
| 53 | + </refsect1> |
| 54 | + |
| 55 | + <xi:include xpointer="domxpath.registerphpfunctions..errors" /> |
| 56 | + |
| 57 | + <refsect1 role="returnvalues"> |
| 58 | + &reftitle.returnvalues; |
| 59 | + <simpara> |
| 60 | + &return.void; |
| 61 | + </simpara> |
| 62 | + </refsect1> |
| 63 | + |
| 64 | + <refsect1 role="examples"> |
| 65 | + &reftitle.examples; |
| 66 | + <example> |
| 67 | + <title>スタイルシートから簡単な PHP 関数をコールする例</title> |
| 68 | + <programlisting role="php"> |
| 69 | +<![CDATA[ |
| 70 | +<?php |
| 71 | +$xml = <<<EOB |
| 72 | +<allusers> |
| 73 | +<user> |
| 74 | + <uid>bob</uid> |
| 75 | +</user> |
| 76 | +<user> |
| 77 | + <uid>joe</uid> |
| 78 | +</user> |
| 79 | +</allusers> |
| 80 | +EOB; |
| 81 | +$xsl = <<<EOB |
| 82 | +<?xml version="1.0" encoding="UTF-8"?> |
| 83 | +<xsl:stylesheet version="1.0" |
| 84 | + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 85 | + xmlns:my="urn:my.ns"> |
| 86 | +<xsl:output method="html" encoding="utf-8" indent="yes"/> |
| 87 | +<xsl:template match="allusers"> |
| 88 | + <html><body> |
| 89 | + <h2><xsl:value-of select="my:count(user/uid)" /> users</h2> |
| 90 | + <table> |
| 91 | + <xsl:for-each select="user"> |
| 92 | + <tr> |
| 93 | + <td> |
| 94 | + <xsl:value-of select="my:uppercase(string(uid))"/> |
| 95 | + </td> |
| 96 | + </tr> |
| 97 | + </xsl:for-each> |
| 98 | + </table> |
| 99 | + </body></html> |
| 100 | +</xsl:template> |
| 101 | +</xsl:stylesheet> |
| 102 | +EOB; |
| 103 | +$xmldoc = new DOMDocument(); |
| 104 | +$xmldoc->loadXML($xml); |
| 105 | +$xsldoc = new DOMDocument(); |
| 106 | +$xsldoc->loadXML($xsl); |
| 107 | +
|
| 108 | +$proc = new XSLTProcessor(); |
| 109 | +$proc->registerPHPFunctionNS('urn:my.ns', 'uppercase', strtoupper(...)); |
| 110 | +$proc->registerPHPFunctionNS('urn:my.ns', 'count', fn (array $arg1) => count($arg1)); |
| 111 | +$proc->importStyleSheet($xsldoc); |
| 112 | +echo $proc->transformToXML($xmldoc); |
| 113 | +?> |
| 114 | +]]> |
| 115 | + </programlisting> |
| 116 | + </example> |
| 117 | + </refsect1> |
| 118 | + |
| 119 | + <refsect1 role="seealso"> |
| 120 | + &reftitle.seealso; |
| 121 | + <simplelist> |
| 122 | + <member><methodname>DOMXPath::registerPhpFunctionNS</methodname></member> |
| 123 | + <member><methodname>DOMXPath::registerPhpFunctions</methodname></member> |
| 124 | + <member><methodname>XSLTProcessor::registerPhpFunctions</methodname></member> |
| 125 | + </simplelist> |
| 126 | + </refsect1> |
| 127 | + |
| 128 | +</refentry> |
| 129 | +<!-- Keep this comment at the end of the file |
| 130 | +Local variables: |
| 131 | +mode: sgml |
| 132 | +sgml-omittag:t |
| 133 | +sgml-shorttag:t |
| 134 | +sgml-minimize-attributes:nil |
| 135 | +sgml-always-quote-attributes:t |
| 136 | +sgml-indent-step:1 |
| 137 | +sgml-indent-data:t |
| 138 | +indent-tabs-mode:nil |
| 139 | +sgml-parent-document:nil |
| 140 | +sgml-default-dtd-file:"~/.phpdoc/manual.ced" |
| 141 | +sgml-exposed-tags:nil |
| 142 | +sgml-local-catalogs:nil |
| 143 | +sgml-local-ecat-files:nil |
| 144 | +End: |
| 145 | +vim600: syn=xml fen fdm=syntax fdl=2 si |
| 146 | +vim: et tw=78 syn=sgml |
| 147 | +vi: ts=1 sw=1 |
| 148 | +--> |
0 commit comments