Reference Manuals

ODFXSLTProcessor

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.

Synopsis

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 );
}

Object Hierarchy

ODFXSLTProcessor

Description

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.

Attribute Details

$cache_dir

public         string         $cache_dir

The location to store preprocessed ODF files

Default value: empty string


$cache_files

private        array          $cache_files

An array of XSLTProcessor objects. One XSLTProcessor for every $container_files after a stylesheet has been loaded and preprocessed.


$cache_force_update

public         bool           $cache_force_update

If this is true, the cache will alwyas be regenerated

Default value: empty string


$container_files

public         array          $container_files

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

Default value: empty string


$generator

protected      string         $generator

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

Default value: empty string


$meta

public         array          $meta

The meta data of the loaded stylesheet

Default value: empty string


$postprocessors

protected      array          $postprocessors

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

Default value: empty string


$preprocessors

protected      array          $preprocessors

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

Default value: empty string


$stylesheet

private        string         $stylesheet

The name of the currently loaded stylesheet


$template_dir

public         string         $template_dir

The location of the ODF template files

Default value: empty string


$temp_dir

public         string         $temp_dir

The location to store temporary files

Default value: empty string


$xmlns

public         array          $xmlns

A list of all namespace URIs

Default value: empty string

Method Details

__construct()

public         ODFXSLTProcessor__construct               ( void );

Create and set up the initial ODFXSLTProcessor object


add_images()

protected      void           add_images                ( object &$dom,
                                                          object &$manifest,
                                                          resource &$zip );

Loop through the ODF document adding the replaced images

&$dom
A DOMDocument object for the file which was parsed
&$manifest
A DOMDocument containing the manifest.xml
&$zip
A valid Zipfile handle to the ODF container

cache_clear()

public         void           cache_clear               ( void );

Clear the cache file associated with the stylesheet


cache_get_filename()

protected      string         cache_get_filename        ( string $template_name );

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

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

cache_update()

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.

$template_name
Path to a template to create a cache for

convert_to_xslt()

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

$contents
A single ODF XML file as text

expand_filename()

protected      string         expand_filename           ( string $filename );

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

$filename
The path to expand

import_stylesheet()

public         void           import_stylesheet         ( string $stylesheet );

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

$stylesheet
Path to a stylesheet

load_meta()

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.

&$zip
A valid Zipfile handle to the ODF container

register_postprocessor()

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.

$function
A function in a format that is callable by PHP's call_user_func()
&$user_data
An arbitraty variable that will be passed back to the postprocessor

register_preprocessor()

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.

$function
A function in a format that is callable by PHP's call_user_func()
&$user_data
An arbitraty variable that will be passed back to the preprocessor

remove_images()

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

&$dom
A DOMDocument object for the file which was parsed
&$manifest
A DOMDocument containing the manifest.xml
&$zip
A valid Zipfile handle to the ODF container

save_meta()

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.

&$zip
A valid Zipfile handle to the ODF container

transform_to_file()

public         void           transform_to_file         ( object $data,
                                                           $destination );

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

$data
A DOMDocument containing the data for the stylesheets
$destination

transform_to_memory()

public         string         transform_to_memory       ( object $data );

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

$data
A DOMDocument containing the data for the stylesheets