mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-27 14:28:56 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@61864 c90b9560-bf6c-de11-be94-00142212c4b1
496 lines
15 KiB
XML
496 lines
15 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.24 $ -->
|
|
<reference id="ref.xslt">
|
|
<title>XSLT functions</title>
|
|
<titleabbrev>XSLT</titleabbrev>
|
|
|
|
<partintro>
|
|
&warn.experimental;
|
|
<sect1 id="xslt.partintro">
|
|
<title>Introduction</title>
|
|
|
|
<sect2 id="xslt.intro">
|
|
<title>About XSLT and Sablotron</title>
|
|
<para>
|
|
XSLT (Extensible Stylesheet Language (XSL)
|
|
Transformations) is a language for transforming XML
|
|
documents into other XML documents. It is a standard
|
|
defined by The World Wide Web consortium (W3C).
|
|
Information about XSLT and related technologies can be
|
|
found at <ulink url="&url.xslt;">&url.xslt;</ulink>.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 id="xslt.install">
|
|
<title>Installation</title>
|
|
<para>
|
|
This extension uses <productname>Sabloton</productname>
|
|
and <productname>expat</productname>, which can both be
|
|
found at <ulink
|
|
url="&url.sablotron;">&url.sablotron;</ulink>. Binaries
|
|
are provided as well as source.
|
|
</para>
|
|
<para>
|
|
On UNIX, run <command>configure</command> with the <option
|
|
role="configure">--with-sablot</option>.
|
|
The <productname>Sablotron</productname> library
|
|
should be installed somewhere your compiler can find it.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 id="xslt.about">
|
|
<title>About This Extension</title>
|
|
<para>
|
|
This PHP extension implements support
|
|
<productname>Sablotron</productname> from Ginger Alliance
|
|
in PHP. This toolkit lets you transform
|
|
XML documents into other documents, including new XML
|
|
documents, but also into HTML or other target formats. It
|
|
basically provides a standardized and portable template
|
|
mechanism, separating content and design of a website.
|
|
</para>
|
|
</sect2>
|
|
|
|
</sect1>
|
|
</partintro>
|
|
|
|
<refentry id="function.xslt-closelog">
|
|
<refnamediv>
|
|
<refname>xslt_closelog</refname>
|
|
<refpurpose>Clear the logfile for a given instance of Sablotron</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>xslt_closelog</function></funcdef>
|
|
<paramdef>resource <parameter>xh</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
&warn.experimental.func;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>xh</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
A reference to the XSLT parser.
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist></para>
|
|
<para>
|
|
This function returns &false; if <parameter>parser</parameter> does
|
|
not refer to a valid parser, or if the closing of the logfile
|
|
fails. Otherwise it returns &true;.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.xslt-create">
|
|
<refnamediv>
|
|
<refname>xslt_create</refname>
|
|
<refpurpose>Create a new XSL processor.</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>resource <function>xslt_create</function></funcdef>
|
|
<void/>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
&warn.experimental.func;
|
|
<para>
|
|
This function returns a handle for a new XSL processor. This handle
|
|
is needed in all subsequent calls to XSL functions.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.xslt-errno">
|
|
<refnamediv>
|
|
<refname>xslt_errno</refname>
|
|
<refpurpose>Return the current error number</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>int <function>xslt_errno</function></funcdef>
|
|
<paramdef>
|
|
resource <parameter>xh</parameter>
|
|
</paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
&warn.experimental.func;
|
|
<para>
|
|
Return the current error number of the given XSL processor. If
|
|
no handle is given, the last error number that occured anywhere
|
|
is returned.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.xslt-error">
|
|
<refnamediv>
|
|
<refname>xslt_error</refname>
|
|
<refpurpose>Return the current error string</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>mixed <function>xslt_error</function></funcdef>
|
|
<paramdef>
|
|
resource <parameter>xh</parameter>
|
|
</paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
&warn.experimental.func;
|
|
<para>
|
|
Return the current error string of the given XSL processor. If
|
|
no handle is given, the last error string that occured anywhere
|
|
is returned.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.xslt-fetch-result">
|
|
<refnamediv>
|
|
<refname>xslt_fetch_result</refname>
|
|
<refpurpose>Fetch a (named) result buffer</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>string <function>xslt_fetch_result</function></funcdef>
|
|
<paramdef>resource <parameter>xh</parameter></paramdef>
|
|
<paramdef>string <parameter>result_name</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
&warn.experimental.func;
|
|
<para>
|
|
Fetch a result buffer from the XSLT processor identified by
|
|
the given handle. If no result name is given, the
|
|
buffer named "/_result" is fetched.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.xslt-free">
|
|
<refnamediv>
|
|
<refname>xslt_free</refname>
|
|
<refpurpose>Free XSLT processor</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>void <function>xslt_free</function></funcdef>
|
|
<paramdef>
|
|
resource <parameter>xh</parameter>
|
|
</paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
&warn.experimental.func;
|
|
<para>
|
|
Free the XSLT processor identified by the given handle.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.xslt-openlog">
|
|
<refnamediv>
|
|
<refname>xslt_openlog</refname>
|
|
<refpurpose>Set a logfile for XSLT processor messages</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>xslt_openlog</function></funcdef>
|
|
<paramdef>resource <parameter>xh</parameter></paramdef>
|
|
<paramdef>string <parameter>logfile</parameter></paramdef>
|
|
<paramdef>int <parameter>loglevel</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
&warn.experimental.func;
|
|
<para>
|
|
Set a logfile for the XSLT processor to place all of its error
|
|
messages.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.xslt-output-begintransform">
|
|
<refnamediv>
|
|
<refname>xslt_output_begintransform</refname>
|
|
<refpurpose>Begin an XSLT transformation on the output</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>void
|
|
<function>xslt_output_begintransform</function>
|
|
</funcdef>
|
|
<paramdef>
|
|
string <parameter>xslt_filename</parameter>
|
|
</paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
&warn.experimental.func;
|
|
<para>
|
|
This function will begin the output transformation on your data.
|
|
From the point you call <function>xslt_output_begintransform</function>
|
|
till the point you call <function>xslt_output_endtransform</function>
|
|
all output will be transformed through the xslt stylesheet given by
|
|
the first argument.
|
|
</para>
|
|
<para>
|
|
<note>
|
|
<simpara>
|
|
This function does not currently support nested output transformations.
|
|
</simpara>
|
|
</note>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>
|
|
Transforming output through an XSLT stylesheet, using the DOM-XML functions for xml generation
|
|
</title>
|
|
<programlisting role="php">
|
|
<?php
|
|
|
|
$xsl_file = "article.xsl";
|
|
xslt_output_begintransform($xsl_file);
|
|
|
|
$doc = new_xmldoc('1.0');
|
|
$article = $doc->new_root('article');
|
|
|
|
$article->new_child('title', 'The History of South Tyrol');
|
|
$article->new_child('author', 'Sterling Hughes');
|
|
$article->new_child('body', 'Back after WWI, Italy gained South Tyrol from
|
|
Austria. Since that point nothing interesting has
|
|
happened');
|
|
|
|
echo $doc->dumpmem();
|
|
|
|
xslt_output_endtransform();
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.xslt-output-endtransform">
|
|
<refnamediv>
|
|
<refname>xslt_output_endtransform</refname>
|
|
<refpurpose>End an output transformation started with xslt_output_begintransform</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>void
|
|
<function>xslt_output_endtransform</function>
|
|
</funcdef>
|
|
<void/>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
&warn.experimental.func;
|
|
<para>
|
|
The <function>xslt_output_endtransform</function> ends the output transformation
|
|
started by the <function>xslt_output_begintransform</function> function. You must call
|
|
this function in order to see the results of the output transformation.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.xslt-process">
|
|
<refnamediv>
|
|
<refname>xslt_process</refname>
|
|
<refpurpose>Transform XML data through a string containing XSL data</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool
|
|
<function>xslt_process</function>
|
|
</funcdef>
|
|
<paramdef>string <parameter>xsl_data</parameter></paramdef>
|
|
<paramdef>string <parameter>xml_data</parameter></paramdef>
|
|
<paramdef>string <parameter>result</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
&warn.experimental.func;
|
|
<para>
|
|
The <function>xslt_process</function> takes a string containing the XSLT stylesheet as
|
|
its first argument, it takes a second string containing the XML data you want to
|
|
transform and then a third string containing the results of the transformation.
|
|
<function>xslt_process</function> will return &true; on success and &false; on failure,
|
|
to get the error number and error string if an error occurs use the
|
|
<function>xslt_errno</function> and <function>xslt_error</function> functions.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Using the <function>xslt_process</function> to transform three strings</title>
|
|
<programlisting role="php">
|
|
<?php
|
|
|
|
$xslData = '<xsl:stylesheet
|
|
version="1.0"
|
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
|
|
|
<xsl:template match="article">
|
|
<table border="1" cellpadding="2" cellspacing="1">
|
|
<tr>
|
|
<td width="20%">
|
|
&#160;
|
|
</td>
|
|
<td width="80%">
|
|
<h2><xsl:value-of select="title"/></h2>
|
|
<h3><xsl:value-of select="author"/></h3>
|
|
<br/>
|
|
|
|
<xsl:copy-of select="p"/>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</xsl:template>
|
|
|
|
</xsl:stylesheet>';
|
|
|
|
$xmlData = '<?xml version="1.0"?>
|
|
<article>
|
|
<title>Learning German</title>
|
|
<author>Sterling Hughes</author>
|
|
<p>
|
|
Essential phrases:
|
|
<br/>
|
|
K&#246;nnen Sie mir sagen, wo die Toilette ist?<br/>
|
|
Ein grosses Bier, bitte!<br/>
|
|
Noch eins, bitte.<br/>
|
|
</p>
|
|
</article>';
|
|
|
|
if (xslt_process($xslData, $xmlData, $result)) {
|
|
echo "Here is the brilliant in-depth article on learning";
|
|
echo " German: ";
|
|
echo "<br>\n<br>";
|
|
echo $result;
|
|
} else {
|
|
echo "There was an error that occurred in the XSL transformation...\n";
|
|
echo "\tError number: " . xslt_errno() . "\n";
|
|
echo "\tError string: " . xslt_error() . "\n";
|
|
exit;
|
|
}
|
|
?>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.xslt-run">
|
|
<refnamediv>
|
|
<refname>xslt_run</refname>
|
|
<refpurpose>Apply a XSLT stylesheet to a file.</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>xslt_run</function></funcdef>
|
|
<paramdef>resource <parameter>xh</parameter></paramdef>
|
|
<paramdef>string <parameter>xslt_file</parameter></paramdef>
|
|
<paramdef>string <parameter>xml_data_file</parameter></paramdef>
|
|
<paramdef>string <parameter>result</parameter></paramdef>
|
|
<paramdef>array <parameter>xslt_params</parameter></paramdef>
|
|
<paramdef>array <parameter>xslt_args</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
&warn.experimental.func;
|
|
<para>
|
|
Process the xml_data_file by applying the xslt_file stylesheet to
|
|
it. The stylesheet has access to xslt_params and the processor
|
|
is started with xslt_args. The result of the XSLT transformation
|
|
is placed in the named buffer (default is "/_result").
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.xslt-set-sax-handler">
|
|
<refnamediv>
|
|
<refname>xslt_set_sax_handler</refname>
|
|
<refpurpose>Set SAX handlers for a XSLT processor</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>xslt_set_sax_handler</function></funcdef>
|
|
<paramdef>resource <parameter>xh</parameter></paramdef>
|
|
<paramdef>array <parameter>handlers</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
&warn.experimental.func;
|
|
<para>
|
|
Set SAX handlers on the resource handle given by
|
|
<parameter>xh</parameter>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.xslt-transform">
|
|
<refnamediv>
|
|
<refname>xslt_transform</refname>
|
|
<refpurpose>Perform an XSLT transformation</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool
|
|
<function>xslt_transform</function>
|
|
</funcdef>
|
|
<paramdef>string <parameter>xsl</parameter></paramdef>
|
|
<paramdef>string <parameter>xml</parameter></paramdef>
|
|
<paramdef>string <parameter>result</parameter></paramdef>
|
|
<paramdef>string <parameter>params</parameter></paramdef>
|
|
<paramdef>string <parameter>args</parameter></paramdef>
|
|
<paramdef>string <parameter>resultBuffer</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
&warn.experimental.func;
|
|
<para>
|
|
The <function>xslt_transform</function> provides an interface to sablotron's
|
|
more advanced features without requiring you to use the resource API.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
</reference>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|