Introduction to XSLT
XSLT, the Extensible Style-sheet Language for Transformation, is an official World Wide Web Consortium (W3C) recommendation that provides a flexible, powerful syntax for defining rules that can be manipulated by XSLT processor to transform single or multiple XML documents into other form – an HTML document, a Portable Document Format (PDF) file, a Virtual Reality Modeling Language (VRML) file, a Scalable Vector Graphics (SVG) file, a Joint Photographic Experts Group (JPEG) file, a flat text file, Java code, and many more (Tidwell 1).
“XSLT makes use of the expression language defined by XPath for selecting elements for processing, for conditional processing and for generating text” (W3C 3).
Extensions
To give the nice visual representation to the output, the data has been arranged appropriately in table and div elements. The presentational properties for both the elements like width, background colors, font sizes, font colors, and many more, have been specified in a separate Cascading Style Sheet (CSS) to give the soothing effects.
Problems encountered
Although the task was quite interesting and I have learned a lot about new technologies and terminologies – Extensible Markup Language (XML), Extensible Style-sheet Language for Transformation (XSLT), XPath (a language for navigating in XML documents), XLink (a standard way for creating hyperlinks in XML documents), XPointer (a standard way to allow hyperlinks to point to more specific parts in the XML documents) and more, the task was very challenging and time-consuming at the same time. Honestly speaking, I was stuck at many points during implementing the XSLT code due to which I was forced to do a lot of searching on Internet and relevant material. Following is the list of problems that I faced while working on the task:
Lack of required knowledge
The very first problem in doing this assignment was lack of my knowledge. For me, most of the involved technologies and terminologies were new. I was somewhat aware of the XML but of the beginners level. Other than XML, I was completely new to XSLT, XPath and others. Due to this lack of knowledge, I had no other option but to first go through all the lectures thoroughly and refer to online tutorials and materials. This procedure alone consumed 4-5 days. After that only I was able to start writing the code.
Input from multiple documents
This was the most frustrating part of the assignment. I first referred to the article whose link was mentioned in the instruction file. I read the article like dozens of time and even followed the example in the article correctly, but no use. Speaking frankly, inspired by the article, what I was trying to do was to merge the two documents, which was of course, not the right logic. I spent like 2-3 days just to sort out this problem. Eventually, I figured out the solution; rather than trying to merge the documents, I used the document function to read the required data from the external XML source.
Sorting the district names
Apparently it was a simple task to sort the district names and for this purpose, I simply included the sort element within for element as I had seen in many examples. But to my surprise, when I executed the code, I saw no result – means the output was not in alphabetical order as expected. I thoroughly checked the code dozens of times and even consulted to online tutorials, but no use. I again searched for more examples on Internet and in one example I read that the sort element can also be used within apply-templates element. And, when I tried the same logic, it worked. However, it took me a whole day to figure out the solution.
Reading RSS feed
After successfully reading and transforming the first three XML files, I was very much confident about the last file as I was expecting it be dealing it the same way I did the first three file. But I was wrong. I tried a lot to read the contents of this last file, an RSS feed, but no luck. On close examination, the first clue I found was the namespace prefix rdf in the root element. Well, this was something different from the first three files.
So, I searched on Internet to deal with namespaces in XSLT and soon I found the solution – I was only required to add the rdf namespace declaration in the stylesheet element of the XSLT code. After doing that I was expecting to get everything right! But that was not the case. Still, I was not able to read the contents. I again referred to many online blogs, examples and forums for the solution and again it would me a day to figure out the solution. Finally, I found one more clue. I added another namespace declaration, rss, in the stylesheet element. Luckily, it worked. By end of this last file, I was amazed to see how much it was complicated to read an RSS feed as compared to simple XML files.
Works Cited
Tidwell, Doug. XSLT. California: O’Reilly Media, Inc., 2008. Print.
W3C. XSL Transformations (XSLT) Version 1.0. 1999. Web.