Once I've programmed the PHP part of the prototype, I had to program the other part of the project: the XSLT file.
Let's go back for a while; the main purpose of the project is, having a syllabi (OpenSyllabus XML course file), I have to make a moodle course automatically according to that syllabi.
Moodle courses can be saved as XML files and be restored with that XML file. With this premise, and knowing that syllabi are also XML files, we can see that we need to transform in some way the syllabi into a Moodle course. The way for doing it is called XSLT (eXtensible StyleSheet Language Tranform).
The process for making the XSL file:
- First, having a syllabi example, I've made manually a Moodle course.
- Then, I've stored the XML file into my computer to work with it (making a backup of the course). Now, the objective is to transform the syllabi XML file into a Moodle XML course file with the aid of XSLT language.
(in the previous entry of my blog I wrote about the PHP part and his relantionship with XSLT part).
I never did any XSL transformation or programmed a XSL file, and I needed learning some advanced XSL features immediatelly not recommended for a newbie who wants to learn XSL as a hobby :). Also I had to adapt the xsl syntax to moodle, because Moodle needs "special" considerations:
- Moodle xml files have very separated parts in the document. However, some parts have a very close relationship, and this relation can only be linked with an Identifier. But this identifier needs to be independent of the XML syllabi, so after some heavy research, the XSL function I needed for this was "generate-id" (this function generates a unique ID for a node, ideal for the lesson bucle).
- I didn't know why Moodle, after the point 1 application, gave me errors didn't allow me to create a course. The explanation was that generate-id generates an id like "id7623472". Moodle only reads numbers, not strings!, so I have to discard the "id" string with "substring" xsl function.
- In bucles, I needed incremental variables (aka i++ :)). Nevertheless, "variable" xsl element doesn't allow changing his first assigned value (OMG, problem!), because XSL is a declarative language, not a procedural one like C++ or PHP. The first and valid approach I found to solve this problem was the "number" xsl element. In a bucle, it makes something like a counter, from 1 to N being N the number of iterations. I found it a rustic and 'vaste' method, but valid for my purposes :)
After all these ones, and spending some time, finally I've finished the XSL file and it works perfectly. But this XSL file is built over a syllabi prototype, not over a final version, so I will have to modify it a lot when I recive it.
Now, I've finished all my work on OpenSyllabus integration prototype for Moodlemoot for now until "new external requirements" (probably they will arrive soon).
As you can see, in my blog entries I'm writing about XML files and other kind of resources, but I don't put any example to allow you understanding me clearly. Once I finish the project I will upload all those files and will modify all posts adding to them the mentioned ones (or until my teacher tells me that it could be good to upload them while they are in process).