wiki:XsltMacro

Version 18 (modified by athomas, 8 years ago) (diff)

Disabling AddCommentMacro - too much spam

XSL-Transformation Macro

Description

The XsltMacro allows you to embed the result of an XSL-transformation in a page. It takes two parameters, a stylesheet and a document to transform. These can be an attachment on any wiki-page or ticket, any page from the htdocs area, any file in the repository, or any url (these options are similar to those for Trac's native ImageMacro). For more details see the documentation in the macro.

The macro can either be installed as a simple macro or as a plugin; the use_iframe and use_object options (see below) only work when installed as a plugin.

This macro requires that libxml2, libxslt, and their python bindings are installed.

IFrames/Objects

Because a macro's output is embedded in the html of the wiki page, the xsl-stylesheet must not produce a full html page. As an alternative, you can pass the use_iframe or use_object option to the macro; this will cause the macro put an <iframe> or <object> tag (respectively) into the page instead of the results from the stylesheet. The stylesheet can (and must) then generate a complete html page.

The downside of iframes/objects is that you need to know the height of the result in order to set the height of the iframe/object; otherwise you'll either get extra space at the bottom or you'll have to scroll through the frame. The macro generates some javascript to automatically set this height, but that only works if the user has javascript enabled of course.

Bugs/Feature Requests

Existing bugs and feature requests for XsltMacro are here.

If you have any issues, create a new ticket.

Download

To install as a simple macro, just download this file and put it in your wiki-macros directory.

To install as a plugin, download the zipped source, unzip, change the directory to xsltmacro/0.9, run
python setup.py bdist_egg, and copy the resulting dist/xslt-0.5-pyX.Y.egg to your plugins directory.

Source

You can check out XsltMacro from here using Subversion, or browse the source with Trac.

Example

The following table is produced with this macro call:

[[Xslt(format.xsl, info.xml)]]
Name Address Email
John Smith 42 Easy St johns@cool.com
Mary Francis 1 Heavenly Way maryf@hot.com

Here's how you would tell it to use an iframe:

[[Xslt(format.xsl, info.xml, use_iframe, if_height=500)]]

Recent Changes

[7914] by roadrunner on 2010-05-02 16:32:16
Pass (http) request parameters which start with xp_ to the stylesheet as
additional parameters. This can be useful for example to implement paging.

This closes #5275.

[7913] by roadrunner on 2010-05-02 16:32:04
Simplified parameter extraction a bit.
[7909] by roadrunner on 2010-05-02 07:25:24
Updated to work under trac 0.12, including multi-repository support.

Author/Contributors

Author: roadrunner
Contributors: wuxxin at gmail.com

User Comments

Feel free to leave any comments about the plugin here.

Comment by anonymous on Ma 06 iun 2006 06:46:14 EST

A hacked version of Xslt.py able to use external url's as doc or style.

With this version it is possible to do some cheap rss feed integration. Just point the xml to a http:// url and supply a local stylesheet.

Example RSS Feed conversion (please use your own stylesheet):

  [[Xslt(http://manalang.com/wp-content/rss1.xsl, http://del.icio.us/rss/)]]

Based on xsltmacro-r790.zip

Thank you for your cool plugin,

wuxxin at gmail.com

Comment by roadrunner on Du 18 iun 2006 22:37:02 EST

Excellent idea! Thank you. Committed (with some fixes and cleanups) as rev [906].

Comment by Andrei on Du 17 sep 2006 18:36:25 EST

I would like to transform RSS output from WordPress and use Trac as my homepage and include a side blog section that links to the real blog.

Comment by roadrunner on Sat Sep 30 19:10:49 2006

You could probably (mis)use the wiki-toc css class for this (or better: provide some css of your own) and use a stylesheet along the lines of (untested):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>

  <xsl:template match="channel">
    <div class="wiki-toc">
      <h4><a href="{link}"><xsl:value-of select="title"/></a></h4>
      <ol>
        <xsl:apply-templates select="item"/>
      </ol>
    </div>
  </xsl:template>

  <xsl:template match="item">
    <li>
      <a href="{link}" title="{description}"><xsl:value-of select="title"/></a>
    </li>
  </xsl:template>
</xsl:stylesheet>

Comment by anonymous on Tue Dec 26 02:07:17 2006

iframe is non-standard nowadays, is it possible to produce "object" tags instead too?

Comment by anonymous on Tue Dec 26 02:07:20 2006

iframe is non-standard nowadays, is it possible to produce "object" tags instead too?

Comment by roadrunner on Wed Jan 3 18:56:25 2007

Done. Available in the new 0.5 release.

Attachments (2)

Download all attachments as: .zip