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 ExceptionHandler's for display to the user.

Methods

boolean __construct(string $xml, string $xsl)

The XsltProcess constructor takes a two parameters for the XML and the XSL and initialises the $this->_xml and $this->_xsl variables. If an XSLTProcessor is not available, this function will return false

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', 'xsl' or xsd

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 trapXSDError(integer $errno, integer $errstr, integer $errfile, integer $errline)

A custom error handler especially for XSD errors.

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

A custom error handler especially for XSL errors.

See Also
boolean validate(string $xsd, string $xml)

That validate function takes an XSD to valid against $this->_xml returning boolean. Optionally, a second parameter $xml can be passed that will be used instead of $this->_xml.

Parameters
  • $xsd stringThe XSD to validate $this->_xml against

  • $xml string(optional) If provided, this function will use this $xml instead of $this->_xml.

Returns

Returns true if the $xml validates against $xsd, false otherwise. If false is returned, the errors can be obtained with XSLTProcess->getErrors()

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