XSL Plugin

Last modified by Vincent Massol on 2021/03/17 21:54

cogTransform external XML content into a XWiki page
TypePlugin
Category
Developed by

xwiki:XWiki.MarcoLinuZ

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

For example it can be used to retrieve, restyle and show external RSS contents into "dynamic" panels.

To work properly the plugin needs an XSL template that transforms the original source into the desired HTML code.

In this plugin's distribution file you'll find an "example" directory containing a simple XSL stylesheet that transform an RSS 2.0 feed into an HTML fragment.

How to use it

  • First of all you need a new Wiki page, so create it.
  • Now you have to attach the "example/rss2xhtml.xsl" file (included into the package) to the page.
  • Go to edit the page and add the following snippet code (change the URIs with something that works ;O):
$xwiki.xslURITransformer.cachedTransformURI("http://rss.host/path/to/the/rssfeed.xml","http://your.wiki.host/xwiki/bin/download/path/to/the/attached/rss2xhtml.xsl", "900")
  • Save the page and enjoy the included and reformatted rss ;O)

How does it works

The plugin uses 2 http connections to fetch the source and the xsl (that i often attach to the same page) and performs the transformation.

It has 2 functions that performs the same work but in 2 different ways:

  • $xwiki.xslURITransformer.cachedTransformURI(SourceURI,XSLURI,Timeout)
  • $xwiki.xslURITransformer.transformURI(SourceURI,XSLURI)

Common parameters:

The "SourceURI" parameter is the full URI of the resource that you want include.

The "XSLURI" parameter is the full URI of the XSL stylesheet to use for the transformation (if you followed my instructions you will find it attached to the page)

The "normal" version performs all the tasks every time the page is viewed (with lot of http traffic to fetch the resources and cpu usage for the transformation).

Cached Version:

The "cached" version has an extra "timeout" parameter that specify the amount of seconds to consider the resource as valid. This function maintains an internal cache of the transformed resources and send them back to the client without perform the whole work every time. The resource is fetched again after it expires (with a great increment of speed and a better memory usage).

Final notes

  • This whole package is released under Apache License.

Prerequisites & Installation Instructions

Follow these steps:

  • Add the JAR in your container classpath (WEB-INF/lib)
  • Edit xwiki.cfg and add the following line to the list of plugins :
    xwiki.plugins=\
          [...]
           ... ,\
         <plugin package>
  • Restart your container
  • Verify the plugin is properly installed by typing the following in a wiki page :
    {{velocity}}
    $xwiki.<plugin name>.name
    {{/velocity}}

    If the installation has been successful, you will see <plugin name>.

  • Copy all the jars from the "dist/lib" directory into the "WEB-INF/lib" of your XWiki installation.
  • Edit your "WEB-INF/xwiki.cfg" and add the following line into the "xwiki.plugins" section:
    com.xpn.xwiki.plugin.xsltransformer.XslURITransformerPlugin
  • At the end of the same file, append the following lines (WEB-INF/xwiki.cfg)
    #XSLTransormer Plugin configuration parameters
    xwiki.xsluritransformer.debug=disabled
    xwiki.xsluritransformer.connectiontimeout=15000
    xwiki.xsluritransformer.fallbackencoding=UTF-8
  • Restart your XWiki

Release Notes

v0.1

This is a simple plugin that lets you *include* and *transform* an external content into any xwiki page. Actually I used it to show external RSS contents into "dynamic" panels.

  • A precompiled version (only for JDK 1.5) is available into the dist/lib directory of the package.
  • you can build the whole project by typing:
    {code}
    ant -f ant/build.xml dist
    {code}

Get Connected