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@40729 c90b9560-bf6c-de11-be94-00142212c4b1
490 lines
14 KiB
XML
490 lines
14 KiB
XML
<reference id="ref.xslt">
|
||
<title>XSLT functions</title>
|
||
<titleabbrev>XSLT</titleabbrev>
|
||
|
||
<partintro>
|
||
<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>
|
||
<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>
|
||
<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>
|
||
<parameter><optional>int xh</optional></parameter>
|
||
</paramdef>
|
||
</funcprototype>
|
||
</funcsynopsis>
|
||
<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>
|
||
<parameter><optional>int xh</optional></parameter>
|
||
</paramdef>
|
||
</funcprototype>
|
||
</funcsynopsis>
|
||
<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>
|
||
<parameter>int xh</parameter>
|
||
<parameter><optional>string result_name</optional></parameter>
|
||
</paramdef>
|
||
</funcprototype>
|
||
</funcsynopsis>
|
||
<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>
|
||
<parameter>resource xh</parameter>
|
||
</paramdef>
|
||
</funcprototype>
|
||
</funcsynopsis>
|
||
<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>
|
||
<parameter>resource xh</parameter>
|
||
<parameter>string logfile</parameter>
|
||
<parameter><optional>int loglevel</optional></parameter>
|
||
</paramdef>
|
||
</funcprototype>
|
||
</funcsynopsis>
|
||
<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>
|
||
<parameter>string xslt_filename</parameter>
|
||
</paramdef>
|
||
</funcprototype>
|
||
</funcsynopsis>
|
||
<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>
|
||
<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>
|
||
<parameter>string xsl_data</parameter>
|
||
<parameter>string xml_data</parameter>
|
||
<parameter>string result</parameter>
|
||
</paramdef>
|
||
</funcprototype>
|
||
</funcsynopsis>
|
||
<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%">
|
||
|
||
</td>
|
||
<td width="80%">
|
||
<h2><xsl:value-of select="title"/></h2>
|
||
<h3><xsl:value-of select="author"/></h3>
|
||
<br/>
|
||
|
||
<xsl:value-of select="body"/>
|
||
</td>
|
||
</tr>
|
||
</table>
|
||
</xsl:template>
|
||
|
||
</xsl:stylesheet>';
|
||
|
||
$xmlData = '
|
||
<?xml version="1.0"?>
|
||
<article>
|
||
<title>Learning German</title>
|
||
<author>Sterling Hughes</author>
|
||
<body>
|
||
Essential phrases:
|
||
<br/>
|
||
K<>nnen Sie mir sagen, wo die Toilette ist?<br/>
|
||
Ein grosses Bier, bitte!<br/>
|
||
Noch eins, bitte.<br/>
|
||
</body>
|
||
</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>
|
||
<parameter>resource xh</parameter>
|
||
<parameter>string xslt_file</parameter>
|
||
<parameter>string xml_data_file</parameter>
|
||
<parameter><optional>string result</optional></parameter>
|
||
<parameter><optional>array xslt_params</optional></parameter>
|
||
<parameter><optional>array xslt_args</optional></parameter>
|
||
</paramdef>
|
||
</funcprototype>
|
||
</funcsynopsis>
|
||
<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>
|
||
<parameter>resource xh</parameter>
|
||
<parameter>array handlers</parameter>
|
||
</paramdef>
|
||
</funcprototype>
|
||
</funcsynopsis>
|
||
<para>
|
||
Set SAX handlers on the resource handle given by xh.
|
||
</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>
|
||
<parameter>string xsl</parameter>
|
||
<parameter>string xml</parameter>
|
||
<parameter>string result</parameter>
|
||
<parameter>string params</parameter>
|
||
<parameter>string args</parameter>
|
||
<parameter>string resultBuffer</parameter>
|
||
</paramdef>
|
||
</funcprototype>
|
||
</funcsynopsis>
|
||
<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:
|
||
-->
|