\ODFXSLTProcessor

Holds an ODF-XSLT sylesheet and allows mutiple transformations to ODF using different XML documents

To use it, simply instanciate it, load it with a stylesheet (either an ODF zipfile containing XSLT stylesheets or an ODF document with ODF-XSLT markup) and call one of the transformto* functions with the XML data.

Summary

Methods
Properties
Constants
__construct()
register_preprocessor()
register_postprocessor()
import_stylesheet()
transform_to_memory()
transform_to_file()
cache_clear()
$temp_dir
$cache_dir
$template_dir
$container_files
$cache_force_update
$xmlns
$meta
No constants found
load_meta()
save_meta()
add_images()
remove_images()
expand_filename()
cache_get_filename()
cache_update()
convert_to_xslt()
$generator
$preprocessors
$postprocessors
N/A
No private methods found
No private properties found
N/A

Properties

$temp_dir

$temp_dir : string

Type

string — The location to store temporary files

$cache_dir

$cache_dir : string

Type

string — The location to store preprocessed ODF files

$template_dir

$template_dir : string

Type

string — The location of the ODF template files

$container_files

$container_files : array

Type

array — An array of filenames inside the ODF document that must be processed.

$cache_force_update

$cache_force_update : boolean

Type

boolean — If this is true, the cache will alwyas be regenerated

$xmlns

$xmlns : array

Type

array — A list of all namespace URIs

$meta

$meta : array

Type

array — The meta data of the loaded stylesheet

$generator

$generator : string

Type

string — The meta:generator string to be used. Classes that derive from ODFXSLTProcessor should change this variable.

$preprocessors

$preprocessors : array

Type

array — An array of preprocessors in the format array('function' => $function, 'user_data' => &$user_data)

$postprocessors

$postprocessors : array

Type

array — An array of postprocessors in the format array('function' => $function, 'user_data' => &$user_data)

Methods

__construct()

__construct() 

Create and set up the initial ODFXSLTProcessor object

register_preprocessor()

register_preprocessor(mixed  $function,   $user_data = null) : void

Register a preprocessor with the template engine. Preprocessor are in the form of function($source, &$ODFXSLTProcessor, &$user_data) and are executed in the order they are registered. They are called after a document has been loaded from the cache but before XSLT processing. Throws an exception on failure.

Parameters

mixed $function

A function in a format that is callable by PHP's call_user_func()

$user_data

register_postprocessor()

register_postprocessor(mixed  $function,   $user_data = null) : void

Register a postprocessor with the template engine. Postprocessor are in the form of function($source, &$ODFXSLTProcessor, &$user_data) and are executed in the order they are registered. They are called after a document has been processed by the XSLT processor but before the result is saved or returned. Throws an exception on failure.

Parameters

mixed $function

A function in a format that is callable by PHP's call_user_func()

$user_data

import_stylesheet()

import_stylesheet(string  $stylesheet) : void

Import the $container_files from $stylesheet and run them through the preprocessors.

Parameters

string $stylesheet

Path to a stylesheet

transform_to_memory()

transform_to_memory(object  $data) : string

Process the ODF template with the data and return the resulting ODF

Parameters

object $data

A DOMDocument containing the data for the stylesheets

Returns

string —

The contents of the resulting ODF file

transform_to_file()

transform_to_file(object  $data,   $destination) : void

Process an ODF template with the data and save the result to $destination

Parameters

object $data

A DOMDocument containing the data for the stylesheets

$destination

cache_clear()

cache_clear() : void

Clear the cache file associated with the stylesheet

load_meta()

load_meta(  $zip) : void

Load the metadata from meta.xml into $this->meta. If there are multiple entries of the same element, the last one is used. See the constructor for a list of meta elements that is loaded.

Parameters

$zip

save_meta()

save_meta(  $zip) : void

Update meta.xml with the values from $this->meta. Note that if meta.xml contains duplicate elements this function will remove them all and replace them with a single value as specified by $this->meta.

See the constructor for teh list of affected meta elements.

Parameters

$zip

add_images()

add_images(  $dom,   $manifest,   $zip) : void

Loop through the ODF document adding the replaced images

Parameters

$dom
$manifest
$zip

remove_images()

remove_images(  $dom,   $manifest,   $zip) : void

Step through all draw:image elements and remove the image from the ODF container if there is an XSLT directive in it that replaces the image

Parameters

$dom
$manifest
$zip

expand_filename()

expand_filename(string  $filename) : string

Expand a template name to a full, absolute path if it's not already an absolute path

Parameters

string $filename

The path to expand

Returns

string —

An absolute path

cache_get_filename()

cache_get_filename(string  $template_name) : string

Return a full path to the cache file belonging to $template_name

Parameters

string $template_name

The name of the template file to find the cache path for

Returns

string —

A path to the cache file

cache_update()

cache_update(string  $template_name) : void

Generate a new cache for $template_name. This function also converts the $container_files from marked-up ODF to XSLT if it's not XSLT already.

Parameters

string $template_name

Path to a template to create a cache for

convert_to_xslt()

convert_to_xslt(string  $contents) : string

Convert an ODF XML file to XSLT according to the ODF-XSLT markup (see documentation). Takes the XML as string and returns the XSLT as string

Parameters

string $contents

A single ODF XML file as text

Returns

string —

An XSLT document as text