Why is XSLT used by many web applications?
closed as not constructive by ChrisF♦ Feb 14 '12 at 23:42
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.
XSLT is a relatively easy way to manipulate data provided on XML-form.
The combination of easy generation of output data on XML-form, and the SQL-ish ability for the XPath queries to slice through the DOM-tree in many, many ways aggregating data is very powerful.
Because you can do so much with so little.
XSLT allows you to transform a (number of) well-formed XML document(s) or fragment(s) into something else, such as:
You can also write sophisticated rules to take decisions on the data in the source XML file(s) along with some parameterization.
There are functions available for processing - similar to SQLite.
The manipulation of hierarchical data is awesome - you can have rules that match tree structures like RegEx's match text strings.
It has a very low barrier to entry - just need a text editor and a modern Browser.
At one company I worked for, we developed a system where 3 well-structured XML files CustomerRequirements.xml, Specifications.xml, TestCases.xml could be run through a variety of XSLT transformations to produce:
Of course, all the interesting information had to be contained in the XML files for the XSLT to be able to generate these outputs, but, with a little bit of thought, this was all made possible.
Of course, we built the XSLT step into our build process to make sure all docs were always up-to-date.
In fact, it encouraged the developers to contribute to the documentation because it felt more like code and lived in version control.
Because it works.
Given that a) XML is in widespread use (from services and as a data storage format) and b) easy to generate you have a lot of data that is available or easily made available as XML.
So, given that you have data in XML format the ability to render it to another format (to restructure the data or for display) using a standard "tool" is very useful, XSLT is the tool and it makes things fairly easy and allows you to do relatively complex things.
I have two use cases:
Its not the only way to achieve this sort of result - but it works and is widely supported.
The first web framework (to my knowledge) that used XSLT extensively for web applications was Apache Cocoon. It also incorporated almost every XML technology out there. The reasoning behind the choice for the framework was two fold:
Essentially, you could create an entirely functional web site that was complete, and then dress it any way you like depending on the setting. The ideas and concepts are powerful, but in the end, developers were required to learn a heck of a lot to become marginally useful with it.
However, it is still true that XSLT allows you much more freedom over the layout than simple HTML and CSS does.
But it can also (like many other tools):
Personally I have used it quite a lot do develop small widgets with different configuration options and styles for websites where the presentation format changed betweens portals but used the same original data. I also often used it to transform database data to JSON data (dump DB to XML then create a JSON tree structure).