General developer forum

Using XSLT to transform course archive content

This discussion has been locked because a year has elapsed since the last post. Please start a new discussion topic.
Using XSLT to transform course archive content
A question came up in the Forum module discussion today regarding saving course Forums as HTML. I've responded there briefly re a solution we came up with but thought I'd share it here with more technical detail to get a few more eyeballs on it and sanity check our approach.

In a nutshell, we have an XSLT file takes forum discussions and posts in a moodle.xml file from a course backup archive and renders them out to an HTML file. The rendered page is portable and contains the discussions and posts in their original structure but without the original Moodle theme and header/footer. It also includes some JavaScript which lets the reader expand/collapse the discussions.

There is obviously some risk that the moodle.xml schema might change over time but updating the XPath statements for major versions of Moodle wouldn't be too much of a chore. There are no custom or extension functions in the XSLT file so it should run happily on any platform that has an XSLT engine installed (sablotron, libxslt, saxon etc). Having said that, one area where an extension function would be useful is in turning the timestamp integer values from the xml into human-readable textual forms.

We use it from the command-line at the moment but it should be possible to run it as a CGI under any language that has XSLT support (ie most) with an upload form a user could use to submit their archive file. Some of the XPath statements do traverse via the rootnode when looking up user names based on IDs so performance may be a consideration in a CGI usage for a bigger moodle.xml file with lots of discussions/posts.

Be interested in any feedback on the approach and to hear about anyone else doing something similar. You can download the file here and I've attached a screenshot of a sample rendering (customisable thru CSS)

Average of ratings: -
Re: Using XSLT to transform course archive content
Group Core developersGroup Plugin developers
Nice work smile

We had a similar request. We wanted a "snapshot" of a course in a static fashion (forums, tasks, quizzies, etc.) and one of the approaches was to perform an XSLT of moodle.xml. Finally we did the hard way: some PHP functions that export content from modules.

It will be nice to extend this transformation to other modules too.

Thanks for sharing smile


Average of ratings: -
Frank Ralf
Re: Using XSLT to transform course archive content
Group Documentation writersGroup Plugin developers
Just posted regarding a similar question under

Our approach was to convert XML to RTF using XSLT.

Average of ratings: -