Moodle XML Quiz conversion to DOC (via XSLT?)

Moodle XML Quiz conversion to DOC (via XSLT?)

by Sapan Desai -
Number of replies: 13
Hello everyone,

I have done some extensive searching on the Internet and on this forum site as well for my query. I am interested in converting my Moodle XML questions (exported from my Moodle quizzes) to a format viewable in Microsoft Word. I know I can do this via an XSL translation. However, I lack the skills necessary to do this easily.

Anyone know of an existing solution to this problem, or can anyone propose a solution based off my existing template?

Thanks!

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="quiz/question/questiontext">
<p>
<b>Question: </b>
<xsl:value-of select="text"/><br></br>
</p>
</xsl:for-each>
<xsl:for-each select="quiz/question/answer">
<p>
<b>Answer Choices: </b>
<xsl:value-of select="text"/><br></br>
</p>
</xsl:for-each>
<xsl:for-each select="quiz/question/generalfeedback">
<p>
<b>Explanation: </b>
<xsl:value-of select="text"/><br></br>
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Average of ratings: -
In reply to Sapan Desai

Re: Moodle XML Quiz conversion to DOC (via XSLT?)

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hello Sapan,
I do not understand what exactly your problem is. The XSL sheet you have created half works with an XML questions category output file, although it is very incomplete and presents some problems. Are you having problems creating a more complete and reliable XSL sheet, or having problems using it to output formatted in MS Word, or what else?
Joseph
In reply to Joseph Rézeau

Re: Moodle XML Quiz conversion to DOC (via XSLT?)

by Sapan Desai -
What I am searching for is a way to transfer Moodle's XML output to a Word document. I thought XSL sheets would let me do something like that. I have no experience working with XSL and what I submitted was my first attempt. I would appreciate your pointers! Thanks -

SSD
In reply to Sapan Desai

Re: Moodle XML Quiz conversion to DOC (via XSLT?)

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

As I said in my previous message, your XSL sheet is the right idea, but it does not quite work; you'll have to study carefully a questions export moodle XML file to find out about all the various elements and sub-elements in that file in order to write all the necessary "loops" in your XSL sheet.

I suppose that, once you have written the XSL file, you know how to use it to output the contents of the XML file into MS Word™ (or into a browser)? That was my question.

I think if you can come up with a working version of XSL sheet for Moodle questions it would be quite useful for Moodle users. I do not know much about XSL myself (I find it's a horrible languageblack eye) but I'm willing to help.

Joseph

In reply to Joseph Rézeau

Re: Moodle XML Quiz conversion to DOC (via XSLT?)

by Frank Ralf -
Unfortunately, I don't have the time right now to provide a full solution, but I will give some hints which worked for me in a similar case some time ago.

What I would recommend is to use XSLT to generate a RTF (Richt Text Format) file, which under the hood is a plain text file. Here's an example:
{\rtf 
{\fonttbl {\f0 Times New Roman;}} 
\f0\fs60 Hello, World! 
}

You can type this in your favorite text editor, save it as .rtf file and voilá - a valid RTF file. An invaluable resource for everything regarding RTF format is http://interglacial.com/rtf/

hth
Frank

Average of ratings: Useful (1)
In reply to Sapan Desai

Re: Moodle XML Quiz conversion to DOC (via XSLT?)

by Dean Stringer -
How about generating a PDF from the data instead. There are plenty of PDF tools available for PHP. See: http://php.net/pdf

If you really must generate a word compatible format then other than the RTF suggestion of Frank's how about creating a Word-XML formatted file?

You could create a new Word file with a sample of how you would like your Quiz data to look. Save-as the file as XML, extract everything in the XML before the Quiz data to a header file, everything after the Quiz to a footer file, and use XSLT to create the bit in the middle?
In reply to Dean Stringer

Re: Moodle XML Quiz conversion to DOC (via XSLT?)

by Frank Ralf -
Word XML (or Office Open XML as it is now called officially
http://en.wikipedia.org/wiki/Office_Open_XML) is of course a viable solution.

Some more points to consider:

One of the advantages of vintage RTF is its backward compatibility, even across platforms.

One of the main disadvantages is the existing, but poor Unicode support of RTF.

Generating PDF would have to be done from within Moodle (e.g. via a separate module), whereas with a XML/XSLT workflow you could build a standalone solution which could work independently from Moodle with the exported XML files.
Average of ratings: Useful (1)
In reply to Frank Ralf

Re: Moodle XML Quiz conversion to DOC (via XSLT?)

by Jurgis Pralgauskis -
I guess you could get more open source activist support, if You
first make ODT files (also xml based)

and then there are tools around to convert odt2rtf, odt2pdf, odt2doc (mostly ooo based)
for exampe http://user.services.openoffice.org/en/forum/viewtopic.php?f=21&t=2539

ps.: maybe OT, but maybe XForms could be applied in some way (ooo also supports this standart)

In reply to Sapan Desai

Re: Moodle XML Quiz conversion to DOC (via XSLT?)

by Matt Jenner -
Has anything become of this, or is a solution yet to be found?
In reply to Matt Jenner

Re: Moodle XML Quiz conversion to DOC (via XSLT?)

by Frank Ralf -
Hi Matt,

It's still on my agenda but I haven't found the time yet. You might have a look at http://docs.moodle.org/en/XML_FAQ or http://docs.moodle.org/en/Import_and_export_FAQ

What exactly do you want to achieve?

In the meantime perhaps the following posts give you some ideas:

"Create pdf quiz"
http://moodle.org/mod/forum/discuss.php?d=113846

"PDF Exam papers for revision, How Do I Mark Them?"
http://moodle.org/mod/forum/discuss.php?d=110455

hth
Frank
In reply to Sapan Desai

Re: Moodle XML Quiz conversion to DOC (via XSLT?)

by Eoin Campbell -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
I have developed a Moodle Question XML to Word conversion using XSLT. It is available to try out on the www.moodle2word.net website. You can import an XML file, export it as Word, and vice versa.
The questions are converted into structured Word tables, and nearly all question types are supported (except numerical).

Rather than converting XML into RTF or Word 2007 XML format, as suggested, I convert it into a dialect of XHTML which Word fully understands and can style properly, as this is much simpler to generate, and also works across more versions of Word. For example, instead of <h1>...</h1>, I generate <h1 class="MsoHeading1">...</h1>, and Word automatically applies the "Heading 1" style.

I intend to release the XSLT code, but I haven't finalised the table format yet, so I would prefer to hold off until I do.

It is part of a larger project to enable quiz questions to be created and maintained directly in Word.
Average of ratings: Useful (1)
In reply to Eoin Campbell

Re: Moodle XML Quiz conversion to DOC (via XSLT?)

by Beat Z -
Hey,

It looks cool! nice work!
will it also be possible to actualy print the questions as they are in a test. so its posible to do a test on paper as the students in some locations do not have internet access?

thanks for your answer.

best regards

beat
In reply to Beat Z

Re: Moodle XML Quiz conversion to DOC (via XSLT?)

by Eoin Campbell -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
This could be done in either of 2 ways:
1. On the Moodle server, output an appropriate print assessment Word format directly;
2. On your local PC, after downloading the Word file, run a macro to modify the appearance of the tables to present it in print assessment format.

Any print assessment format will probably vary according to personal taste (font size and family, indentation, page breaking etc.) so
I think doing it on the server isn't a good approach.

A VBA macro could do the job a bit more flexibly, and some day soon I might write it to suit.

The macro would need to handle the following:
a. turn off table cell borders
b. shuffle the answer rows, because
the 1st answer may frequently be the right one
(depending on how you created the questions, I think)
c. hide row 2, the table column heading row.
d. hide the feedback and instruction rows
e. hide the last column, containing type and grade
info.

Hiding text is easy, as you can just set the font property 'hidden' to do so.