C.3. Final notes

The above stylesheet was tested using James Clark's XT XSLT processor. I also wrote a C++ implementation. Running both on my computer yielded the results in Table C-1.

Table C-1. Comparing processing speed between between XSLT and C++ for solving N-Queens
Number of Queens Number of Solutions Time to run in XSLT Time to run in C++
4 2 1.0 second 0.065 seconds
6 4 1.5 second 0.065 seconds
8 92 8.5 seconds 0.065 seconds
10 724 3.0 minutes 0.180 seconds

XT is a pretty fast XSLT processor. It is just not optimized for the kind of processing this stylesheet performs. Not only that, while the stylesheet does print all the solutions to the N-Queens problem, it does not print a serial number by each. It turns out that doing so is a non-trivial problem. To achieve this, the stylesheet would need to collect all the valid solutions into a single long string, and only then print them one by one, as opposed to printing each solution the moment it was found. That would probably make it even less efficient. There's no such problem in the C++ program.

This demonstrates that while it is possible to perform general-purpose computations in XSLT, it may be impossible to do so in an efficient manner. In general, the techniques demonstrated in this stylesheet (using loop templates and using strings to represent complex data) do not scale well for large processing tasks.

It is doubtful that this situation will change in the future. XSLT was not design for such tasks. Instead, it provides standard mechanisms for accessing external functionality from an XSLT stylesheet, using extension elements and extension functions.

It is therefore important to assess the practicality of writing a complex processing task in XSLT as opposed to providing it as an extension function. As long as XSLT is used for small amounts of data, such as a single HTML page, the need for portability may well favor implementing the task in straight XSLT. For large amounts of data, such as processing large archives, the loss of portability may well be worth the huge increase in efficiency.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset