RIFE logo
This page last changed on Mar 14, 2008 by jimmy.

Templates can be instantiated by providing an optional TemplateTransformer. These are able to process the raw content of a template before it reaches the parser. Any modifications that are thus performed like this will be seen by the parser engine as if it was the actual content of the template.

One such transformers is able to filter XML through XSLT stylesheets. Below is a very simple example of how to get a template that will be transformed through XSLT :

TemplateTransformerXslt transformer = new TemplateTransformerXslt();
Template template = getXmlTemplate("name", transformer);

The XML template could then have been defined like this for example :

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="templates/view.xsl"?>

With the following stylesheet :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
     xmlns:rife="http://www.uwyn.com/rife/ com.uwyn.rife.template.XsltExtension"
    <xsl:template match="content">
            <link rel="stylesheet" type="text/css" href="[!V  'stylesheet'/]"/>
            <div class="[!V 'divclass'/]">
                <rife:value name="leftcolumn"/>

Note the use of the special <rife:value name="name"/> tag. These tags are RIFE extensions that have been added to the XSLT processor so that you can easily create invisible tags. Otherwise a lot of XSLT noise would have to be added. To make these tags work you should define the correct xmlns:rife namespace in the xsl:stylesheet tag and indicate that the rife prefix refers to an extension element.
The supported tags are the following :

<rife:value name="value"/>
<rife:value name="value">default</rife:value>
<rife:block name="block">content</rife:block>
<rife:blockvalue name="blockvalue">content</rife:blockvalue>
<rife:include name="include"/>

These will thus generate the corresponding invisible comment tags.

Notice that the compact tag format has been used too as attribute values. Xalan (which ships with J2SE 1.4) however by default escapes url strings in html documents. This for example turns the space in a RIFE template tag into %20. To prevent this you're able to explicitly set output properties.
For example like this :

transformer.setOutputProperty(TemplateTransformerXslt.OUTPUT_METHOD, "html");
transformer.setOutputProperty(TemplateTransformerXslt.OUTPUT_USE_URL_ESCAPING, "no");

It's also possible to create a chains of XSLT stylesheets with the following command :


The transformations will be performed in the same order as the order of the filter additions. An XML document stylesheet processing instruction is always the first stylesheet in the filter chain.

Every stylesheet filename will be looked up through the classpath as regular files (not classnames as with RIFE templates).

Document generated by Confluence on Oct 19, 2010 14:57