ODFXSLTProcessor — Holds an ODF-XSLT sylesheet and allows mutiple transformations to ODF using different XML documents
ODFXSLTProcessor is part of the PHP-ODF-XSLT package.
class ODFXSLTProcessor { public string $cache_dir private array $cache_files public bool $cache_force_update public array $container_files protected string $generator public array $meta protected array $postprocessors protected array $preprocessors private string $stylesheet public string $template_dir public string $temp_dir public array $xmlns public ODFXSLTProcessor __construct ( void ); protected void add_images ( object &$dom, object &$manifest, resource &$zip ); public void cache_clear ( void ); protected string cache_get_filename ( string $template_name ); protected void cache_update ( string $template_name ); protected string convert_to_xslt ( string $contents ); protected string expand_filename ( string $filename ); public void import_stylesheet ( string $stylesheet ); protected void load_meta ( resource &$zip ); public void register_postprocessor ( mixed $function, mixed &$user_data ); public void register_preprocessor ( mixed $function, mixed &$user_data ); protected void remove_images ( object &$dom, object &$manifest, resource &$zip ); protected void save_meta ( resource &$zip ); public void transform_to_file ( object $data, $destination ); public string transform_to_memory ( object $data ); }
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 transform_to_* functions with the XML data.
public string $cache_dir
The location to store preprocessed ODF files
Default value: empty string
private array $cache_files
An array of XSLTProcessor objects. One XSLTProcessor for every $container_files after a stylesheet has been loaded and preprocessed.
public bool $cache_force_update
If this is true, the cache will alwyas be regenerated
Default value: empty string
public array $container_files
An array of filenames inside the ODF document that must be processed.
Default value: empty string
protected string $generator
The meta:generator string to be used. Classes that derive from ODFXSLTProcessor should change this variable.
Default value: empty string
public array $meta
The meta data of the loaded stylesheet
Default value: empty string
protected array $postprocessors
An array of postprocessors in the format array('function' => $function, 'user_data' => &$user_data)
Default value: empty string
protected array $preprocessors
An array of preprocessors in the format array('function' => $function, 'user_data' => &$user_data)
Default value: empty string
private string $stylesheet
The name of the currently loaded stylesheet
public string $template_dir
The location of the ODF template files
Default value: empty string
public string $temp_dir
The location to store temporary files
Default value: empty string
public array $xmlns
A list of all namespace URIs
Default value: empty string
public ODFXSLTProcessor__construct ( void );
Create and set up the initial ODFXSLTProcessor object
protected void add_images ( object &$dom, object &$manifest, resource &$zip );
Loop through the ODF document adding the replaced images
public void cache_clear ( void );
Clear the cache file associated with the stylesheet
protected string cache_get_filename ( string $template_name );
Return a full path to the cache file belonging to $template_name
protected void cache_update ( string $template_name );
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.
protected string convert_to_xslt ( string $contents );
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
protected string expand_filename ( string $filename );
Expand a template name to a full, absolute path if it's not already an absolute path
public void import_stylesheet ( string $stylesheet );
Import the $container_files from $stylesheet and run them through the preprocessors.
protected void load_meta ( resource &$zip );
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.
public void register_postprocessor ( mixed $function, mixed &$user_data );
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.
public void register_preprocessor ( mixed $function, mixed &$user_data );
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.
protected void remove_images ( object &$dom, object &$manifest, resource &$zip );
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
protected void save_meta ( resource &$zip );
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.
public void transform_to_file ( object $data, $destination );
Process an ODF template with the data and save the result to $destination
public string transform_to_memory ( object $data );
Process the ODF template with the data and return the resulting ODF