The PXTemplateGenerator generator reads an XML file and is identical to FileGenerator except for one crucial difference: embedded Paloose sitemap variables are expanded. These variables take the form "{module_name:variable_name}". Like any other generator they should always be the first item of a pipeline. So a typical use of PXTemplateGenerator would be:

<map:generators default="file"> <map:generator name="px" src="resource://lib/generation/PXTemplateGenerator"/> ... </map:generators> <map:pipelines> <map:pipeline> <map:match pattern="**.xml"> <map:generate type="px" src="context://admin/{1}.xml" label="xml-content"/> ... </map:match> </map:pipeline> </map:pipelines>

Simple Example

One case where this is very useful is displaying session information, for example personalising an admin session. If the XML file contains:

<t:heading level="1">Welcome, {session:__username}, to the Paloose Admin Page</t:heading>

Assuming the session variable "__username" contains "hsfr" the following will be output into the pipeline:

<t:heading level="1">Welcome, hsfr, to the Paloose Admin Page</t:heading>

In versions after 1.3.4 implicit entities defined by ISOlat1, ISOpub and ISOnum are translated into their numerical form. The EntityTransformer now only handles explicitly declared entities within a DOCTYPE statement within the XML file.

Caching Support (available after Version 1.3.0)

The PXTemplateGenerator component supports caching of the data within the pipeline. The input file is normally checked for well-formedness (no schema validation) but caching the data stores the XML after this process. As a result very little time is saved except on very large XML source files.


Note that if you have an XML file that includes other files (via xinclude), the generator caching will not detect that these other XML files have been modified. If you modify them it is important to clear out the caching to let the cache files to be rebuilt.

Enabling caching is done globally and locally. To turn on caching for all PXTemplateGenerators there is an attribute cachable that should be set to true (true/yes/1). So setting the global flag would be (default is false):

<map:generators default="file"> <map:generator src="resource://lib/generation/PXTemplateGenerator" name="px" cachable="yes"/> </map:generators>

This can be overriden by using the same attribute when the pipeline component is used:

<map:match pattern="*.xml"> <map:generate src="context://content/{1}.xml" label="xml-content" type="px" cachable="no"/> <map:serialize/> </map:match>

The above would turn off the caching for just this instance in the pipeline. It is also possible to change the action of the cache via the query string by using the request parameters. The following would control the generator instance by including the query string "http://[host]/[path-file-name]?cachable=1" or "http://[host]/[path-file-name]?cachable=0"

<map:generators default="file"> <map:generator src="resource://lib/generation/PXTemplateGenerator" name="px" cachable="no"> <map:use-request-parameters>true</map:use-request-parameters> </map:generator> </map:generators> ... <map:match pattern="index.xml"> <map:generate src="context://content/index.xml" type="px" label="index-xml" cachable="{request-param:cachable}"/> <map:serialize type="xml"/> </map:match>
Copyright 2006 – 2023 Hugh Field-Richards. All Rights Reserved.