XSLT functionsXSLTIntroductionAbout XSLT and Sablotron
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 &url.xslt;.
Installation
This extension uses Sabloton
and expat, which can both be
found at &url.sablotron;. Binaries
are provided as well as source.
On UNIX, run configure with the .
The Sablotron library
should be installed somewhere your compiler can find it.
About This Extension
This PHP extension implements support
Sablotron 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.
xslt_closelogClear the logfile for a given instance of SablotronDescriptionbool xslt_closelogresource xhxh
A reference to the XSLT parser.
This function returns false if parser does
not refer to a valid parser, or if the closing of the logfile
fails. Otherwise it returns true.
xslt_createCreate a new XSL processor.Descriptionresource xslt_create
This function returns a handle for a new XSL processor. This handle
is needed in all subsequent calls to XSL functions.
xslt_errnoReturn the current error numberDescriptionint xslt_errnoint xh
Return the current error number of the given XSL processor. If
no handle is given, the last error number that occured anywhere
is returned.
xslt_errorReturn the current error stringDescriptionmixed xslt_errorint xh
Return the current error string of the given XSL processor. If
no handle is given, the last error string that occured anywhere
is returned.
xslt_fetch_resultFetch a (named) result bufferDescriptionstring xslt_fetch_resultint xhstring result_name
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.
xslt_freeFree XSLT processorDescriptionvoid xslt_freeresource xh
Free the XSLT processor identified by the given handle.
xslt_openlogSet a logfile for XSLT processor messagesDescriptionbool xslt_openlogresource xhstring logfileint loglevel
Set a logfile for the XSLT processor to place all of its error
messages.
xslt_output_begintransformBegin an XSLT transformation on the outputDescriptionvoid
xslt_output_begintransformstring xslt_filename
This function will begin the output transformation on your data.
From the point you call xslt_output_begintransform
till the point you call xslt_output_endtransform
all output will be transformed through the xslt stylesheet given by
the first argument.
Transforming output through an XSLT stylesheet, using the DOM-XML functions for xml generation
<?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();
xslt_output_endtransformEnd an output transformation started with xslt_output_begintransformDescriptionvoid
xslt_output_endtransform
The xslt_output_endtransform ends the output transformation
started by the xslt_output_begintransform function. You must call
this function in order to see the results of the output transformation.
xslt_processTransform XML data through a string containing XSL dataDescriptionbool
xslt_processstring xsl_datastring xml_datastring result
The xslt_process 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.
xslt_process will return true on success and false on failure,
to get the error number and error string if an error occurs use the
xslt_errno and xslt_error functions.
Using the xslt_process to transform three strings
<?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%">
</title>
<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>
<br>
Komme sie mir sagen, woe die toilette es?<br>
Eine grande beer bitte!<br>
Noch einem 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;
}
?>
xslt_runApply a XSLT stylesheet to a file.Descriptionbool xslt_runresource xhstring xslt_filestring xml_data_filestring resultarray xslt_paramsarray xslt_args
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").
xslt_set_sax_handlerSet SAX handlers for a XSLT processorDescriptionbool xslt_set_sax_handlerresource xharray handlers
Set SAX handlers on the resource handle given by xh.
xslt_transformPerform an XSLT transformationDescriptionbool
xslt_transformstring xslstring xmlstring resultstring paramsstring argsstring resultBuffer
The xslt_transform provides an interface to sablotron's
more advanced features without requiring you to use the resource API.