public class XsltProcess

class.xsltprocess.php #13

The XsltProcess class is responsible for taking a chunk of XML and applying an XSLT stylesheet to it. Custom error handlers are used to capture any errors that occurred during this process, and are exposed to the ExceptionHandlers for output.

Methods

boolean __construct(string $xml, string $xsl)

The XsltProcess constructor takes a two parameters for the XML and the XSL and initalises the $this->_xml and $this->_xsl. It checks to see if there is an existing XSLTProcessor

Parameters
  • $xml stringThe XML for the transformation to be applied to

  • $xsl stringThe XSL for the transformation

Returns

True if there is an existing XsltProcessor class, false otherwise

void __error(integer $number, string $message, string $file, string $line, string $type)

Writes an error to the $_errors array, which contains the error information and some basic debugging information.

Parameters
  • $type stringWhere the error occurred, can be either 'xml' or 'xsl'

See Also
array getError(boolean $all, boolean $rewind)

Provides an Iterator interface to return an error from the $_errors array. Repeat calls to this function to get all errors

Parameters
  • $all booleanIf true, return all errors instead of one by one. Defaults to false

  • $rewind booleanIf rewind is true, resets the internal array pointer to the start of the $_errors array. Defaults to false.

Returns

Either an array of error array's or just an error array

boolean isErrors()

Returns boolean if any errors occurred during the transformation.

See Also
static boolean isXSLTProcessorAvailable()

Checks if there is an available XSLTProcessor

Returns

True if there is an existing XsltProcessor class, false otherwise

string process(string $xml, string $xsl, array $parameters, array $register_functions)

This function will take a given XML file, a stylesheet and apply the transformation. Any errors will call the error function to log them into the $_errors array

Parameters
  • $xml stringThe XML for the transformation to be applied to

  • $xsl stringThe XSL for the transformation

  • $parameters arrayAn array of available parameters the XSL will have access to

  • $register_functions arrayAn array of available PHP functions that the XSL can use

Returns

The string of the resulting transform.

See Also
void trapXMLError(integer $errno, integer $errstr, integer $errfile, integer $errline)

A custom error handler especially for XML errors.

See Also
void trapXSLError(integer $errno, integer $errstr, integer $errfile, integer $errline)

A custom error handler especially for XSL errors.

See Also

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details