Xml – point creating a site using XSLT


Is this technology still popular?

I want to make a website which automatically transforms XSLT files. It should work like this:
When a user accesses the site, a single handler would accept his request and then find a suitable XML for it (according to the URL requested) and transform it using its attached XSL file.

I want to do this in order to make it easy to update the site using plain XML files (instead of using a full-fledged & expensive CMS system).

What do you say? good idea? bad idea? anyone has a recommendation?


Best Solution

Back in 2002-2003 I did a lot with XSLT (and some more in 2006-2007). Your mileage on this will vary but honestly I would avoid it, for several reasons:

  • The syntax is a blinding headspin, hard to learn, hard to get right and just plain gives you a headache. The templates themselves aren't too bad but throw in some gnarly XPath expressions and it just hurts;
  • For reasonably sized documents and transforms it is relatively slow. Whether or not it's slow enough to be relevant to you is something you'll only find with benchmarking your scenario so don't take this as a blanket rule, more of a cautionary tale or a caveat;
  • Error messages just aren't that useful and it can be hard to figure out problems. Unlike a more traditional approach, you can't whip out a debugger and step through an XSLT;
  • Generating HTML with any modern Web-flavoured language (C#, Java, PHP, Python, Ruby, etc) is trivial, straightforward, easy to log and easy to debug;
  • Manipulating XML is arguably more tedious and produces more code that directly manipulating objects and converting them into markup. This of course will vary by what tools your chosen language provides you with.

The only place I can really see having an application for XSLT these days is in consuming Web services that produce XML (lots produce JSON and more easily consumed formats these days).

And even in that case I'd probably still manipulate the XML directly with, say, JAXB in Java (or similar technologies in other languages).

Update: I just came across The Death of XSLT in Web Frameworks. For example:

For example: how to hide the row in table (using different CSS style), based on some CONDITION, with XSLT? See:

  <xsl:attribute name="style">
      <xsl:when test="CONDITION">
        <xsl:value-of select="'visibility: visible'">
        <xsl:value-of select="'visibility: collapse'">

and now the same with JSP 1.x:

<tr style='visibility:<%=CONDITION ? "collapse" : "visible"%>'>

or with JSP 2.x:

<tr style='visibility:${CONDITION ? "collapse" : "visible"}'>

summarized by:

So if you start new project, think twice (or ten times) before jumping into XSLT. And > if you use Eclipse, you can even think twice before using JSP/JSTL. Velocity or > FreeMarker might be a better option.

Related Question