While we're waiting for the XSLT 2.0 compliant implementations we can still use good ol' XSLT 1.0, especially with the help of the XSLT support in the .NET Framework 2.0 and Visual Studio 2005.
If you've tried to upgrade a project from version 2003 to 2005 you must have noticed that once the conversion wizard is done you are offered to have a look at the results. The result is just a simple XML file (named UpgradeLog.xml) that has XSLT stylesheet referenced thus when opened from Internet Explorer you get a nicely laid out HTML page.
The XSLT file used can be found in the Visual Studio installation folder - it's in /Common7/Ide/1033. On each conversion this file and associated CSS and 2 GIF files get copied into the solution folder and are referenced from the resulting HTML file. XSLT file can be replaced with your own implementation, but the CSS and GIF files are nowhere to be found. On top of all this, if you open the UpgradeLog.xml file from Firefox, you will get a following error: Error during XSLT transformation: An unknown XPath extension function was called.
The problem here is that Firefox does not support node-set extension function that is practically mandatory extension for any serious XSLT 1.0 processor (and is one of the reasons XSLT 2.0 would be really nice to have). Another problem is that CSS and 2 GIF files are not present in the filesystem so if you want to customize or completely replace the XSLT you need to refactor it so that it either uses the same styles and GIF files, or rewrite it completely.
Now, why would you want to do that? Well, at least for me, the resulting HTML is not really readable. The most important information - whether conversion succeeded or not and where it failed - is not at all obvious from the output. So I decided to write my own and to make it usable from Firefox too :)
The result is the stylesheet that you can download from here. Just copy it over the default one and enjoy (don't forget to back up the original!). Here's the output from my stylesheet:
As you can see, several things are immediately noticeable - at the very top, there is a reddish circle by the report name - if there were no warnings, this would be a green check-mark (and if there were errors it would be a red cross). For each of the successful conversions you can see green text (whether file was converted or not), otherwise it is reddish when there are warnings and red when there are errors. At the top, you can also see an overall count of errors and warnings.
All in all, just a quick look is enough to verify if things went OK or not. As is also obvious, the conversion now works from Firefox. It doesn't hurt that the XSLT is now self-sufficient and half of the size of Microsoft's implementation :) But that's not all - it should be faster too (not that it matters in this case, though)...
So how did I do it? For a start, I avoided using the node-set extension function. There's nothing wrong with this function - in fact mostly it's crucial to effective XSLT script - but in this case it was not necessary. The main reason Microsoft used it is because the input XML tree was first transformed (twice!) into an intermediary representation in order to simplify the final transform phase. However this could have been avoided due to the reason why all this was done - just to do a relatively simple two-level grouping of nodes.
There is a well-known trick to achieve grouping in XSLT called Muenchian grouping. It is based on the usage of less-known XSLT construct called key. It was still a bit of work to get it right here because the data requires two-level grouping, while most if not all of the examples of xsl:key usage demonstrate simple one-level grouping. I decided to put the result of the first level grouping in a variable and then group over that in exactly the same way. It worked like a charm - the cool thing is that putting nodes in a variable will not require using a node-set afterward to traverse the nodes.
I have also decided to use CSS styling instead of GIF files for the expand/collapse “buttons”. The result is small, efficient and self-sufficient XSLT script that should work in all standard compliant browsers (tested in Firefox and Internet Explorer 6). Enjoy!
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5