Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Why is XSLT used by many web applications?

share|improve this question

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.

    
None. See news.ycombinator.com/item?id=1330607 ... –  gingerbreadboy Feb 16 '11 at 14:24
add comment

6 Answers

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.

share|improve this answer
1  
With the emphasis on the relatively there. You can do some very clever things with XSLT but beyond the most basic transformations it can be quite counter-intuitive unless you're accustomed to pure functional programming. –  glenatron Dec 10 '10 at 14:38
    
@glenatron, it doesn't take much in a declarative language to result in something more complicated than XSLT. Also you can easily adapt a style where the XSLT-document is the resulting output with a few loops here and there. It doesn't HAVE to be functional. –  user1249 Dec 10 '10 at 15:40
    
It depends what you want to do, but some things that are very easy if you're used to regular programming are very hard to do in XSLT. Muenchian grouping being a classic example. –  glenatron Dec 10 '10 at 16:21
    
"Regular programming" evolves. 10 years ago most of the programmers would be puzzled before some code written in FP fashion. Today FP entered mainstream. Same can happen with declarative style XSLT uses. I myself learned a lot doing XSLT. It's not universal, but powerful it is. –  Mladen Jablanović Dec 10 '10 at 21:21
    
@glenatron, Muenchian grouping is just proof that XPath is SQL in disguise, as it creates an index. –  user1249 Dec 14 '10 at 7:10
add comment

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:

  1. Leveraging XML helps to get closer to a semantic web, and XSLT provides a means to present that source XML to different clients (i.e. HTML, SVG, JPG, MS Excel, PDF, etc.).
  2. It helps provide a separation of concerns where the original XML represents your model, the XSLT represents your view, and "actions" represent your controller.

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.

share|improve this answer
add comment

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:

  • an HTML page to serve to the end user.
  • an XML file for input to an external system (e.g. PDF Writer)
  • graphics, something like SVG or another tool.
  • a SQL/CSV/database file for import into an analytics engine
  • source code

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:

  1. Customer-ready Requirements Document, for customer to sign off.
  2. List of work items => agile backlog.
  3. Customer-ready (if they want it) formal Specifications Document.
  4. List of manual tests that can be run by QA team (because code now implemented)
  5. A nicely-formatted QA test sheet for QA person to do manual testing.
  6. A List of Requirements not yet implemented.
  7. Documentation on how to deploy the project, including version info, where to pick up the build, the file 'manifest', etc.

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.

share|improve this answer
add comment

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:

  1. email of an order - we have one routine to generate the XML for an order, we can use multiple templates to format the information in the order for display on screen, to be sent to a client as a confirmation, to be sent to an in house user for process and so on. Because the XSLT files are independent of the application we can make changes to those file with far more flexibility that would be available if the generation were coded into the application directly.

  2. Production of a large directory. In this case we took the same XML and by transforming it one way were able to produce a 500 page PDF in sections complete with page numbering, table of contents, index, etc. By transforming it another way (the same XML but a set of XSLT templates and a small amount of very re-usable code) we had a website with the same information.

Its not the only way to achieve this sort of result - but it works and is widely supported.

share|improve this answer
add comment

It is not controlled by Larry Ellison.

share|improve this answer
add comment

Because:

  • It is close to the data,
  • It is (relatively) easy to generate by meta-programming,
  • It is (relatively) easy to teach to the herd of monkeys editing your websites and just developing small widgets for it,
  • It is very powerful for data transformations,
  • It is fast to process,
  • It is (relatively) easy to maintain.

But it can also (like many other tools):

  • be written in a fairly cryptic fashion,
  • be misused (doing everything with it, or transforming data in an overly inefficient way),
  • be a bad reason for you to store everything in XML when other formats would do.

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).

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.