20

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?

Thanks!

webwise
  • 627
  • 10
  • 22
  • 2
    Using XSLT is certainly a good idea and I use it for several Web sites. But generating dynamically the pages at request-time, like you do, can be slow. Is it really necessary? I prefer to pre-generate the HTML files. – bortzmeyer Apr 01 '09 at 15:08

14 Answers14

26

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:

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

and now the same with JSP 1.x:

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

or with JSP 2.x:

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

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.

cletus
  • 616,129
  • 168
  • 910
  • 942
  • +1: avoid the lure of "all singing, all dancing, all XML". There's no real value in all XML. – S.Lott Feb 18 '09 at 11:26
  • 2
    Actually there are meanwhile quite a few XSLT debuggers, for instance in Visual Studio or Altova's XMLSpy. – Adrian Grigore Feb 18 '09 at 12:13
  • I agree on all those points. Using XSLT is a pain. – Philip Morton Feb 18 '09 at 12:55
  • 1
    Wow, IMHO this is wrong on so many levels. I'll pick on just one point. You can step through an XSLT transform in Visual Studio. Or you can download this excellent tool for free http://sourceforge.net/projects/xselerator/ – Darrel Miller Feb 18 '09 at 13:53
  • Why would someone mark this as offensive?! – Philip Morton Feb 18 '09 at 14:19
  • Indeed. Whoever did should be banned (seriously). – cletus Feb 18 '09 at 14:20
  • /signed - I strongly disagree with your answer, but it's a subjective question (whether marked as such or not) and there's nothing offensive about an honestly expressed opinion – annakata Feb 18 '09 at 14:38
  • The SO FAQ states offensive is for "spam, hate speech, or abuse" which this isn't. http://stackoverflow.com/questions/135685/how-does-the-offensive-flag-work-in-stackoverflow – cletus Feb 18 '09 at 14:43
  • +1 Interesting this answer has the most upvotes and the most comments but was not chosen as the answer. – Jason Slocomb Feb 18 '09 at 19:43
  • It currently stands at 12 upvotes, 5 downvotes and TWO OFFENSIVE VOTES. Thsoe two people need to get a grip (and probably lose 100 rep each or just plain be banned since they obviously can't cope with opinions different to theirs). – cletus Feb 18 '09 at 20:58
  • @cletus: It kind of sounds like /you/ are the one who cannot cope with differing opinions by your rant... – GEOCHET Feb 19 '09 at 00:07
  • @Rich: I can take as many downvotes as you like. I do however take exception to people abusing a feature design to filter out spam and abuse. After all, if everyone went around marking posts they disagreed with as offensive SO would be worse off. Its about being responsible. – cletus Feb 19 '09 at 00:55
  • @cletus: You have just offended me. Prepare to be flagged as such! – GEOCHET Feb 19 '09 at 17:31
  • 6
    Hello!? XSLT 2.0 !? – Max Toro Jan 07 '10 at 01:40
  • 6
    xst 2.0: – Joep Jul 08 '10 at 08:09
  • Altough I completely agree, `Unlike a more traditional approach, you can't whip out a debugger and step through an XSLT` - that is not true, I used some "OxygenXML" product that had some sort of debugging that I can't remember well but was good. And even with that, the language sucked. Not that it helped much. – Camilo Martin Sep 13 '12 at 00:32
  • The big draw of XSL is the very clear separation. During development you can let your business logic generate the XML once and save it in a file, which you can then hand over to a frontend guy to create the whole output (XSLT, CSS, JS, ...) side for it (ideally). As long as your XML Schema doesn't change, the output side will keep working. – DanMan Dec 10 '13 at 19:51
  • 2
    How about just and style the css based on the condition? Then you've got a really simple template, and your styling is dependent on the style sheets. – Pete - MSFT Jul 24 '14 at 02:31
21

Answers based on "the syntax is hard" is no answer at all imho. A). It really isn't, and B). You're supposed to be a programmer, just learn it.

Definitely other technologies are advancing at a pace XSLT hasn't since 2005ish, but it remains a powerful tool which gives you a level of abstraction that, say, asp.net webforms don't, and allows you to provide a general scalable solution to trivially serialise to a range of output formats. It's easy to generate HTML with any given language, it's harder to now extend that to XML, now extend that to JSON, now extend that to CSV.

And cached transforms are plenty fast enough in an environment which is still I/O bound.

OTOH, storing data in XML is generally not a good idea. Far better to store in a DB/mem and serialise as required for all the reasons above.

annakata
  • 74,572
  • 17
  • 113
  • 180
  • 14
    *Answers based on "the syntax is hard" is no answer at all imho. A). It really isn't, and B). You're supposed to be a programmer, just learn it."* I can't believe that was voted up! If your response is valid this so would this: *"Answers saying that coding websites in C++ is too hard is no answer at all imo."* Ludicrious! Programmer productivity is extremely important on the web; why use a tool that makes it many times harder? To *prove* you are a *"worthy"* programmer? Sheesh. – MikeSchinkel Oct 13 '11 at 16:24
  • 1
    @MikeSchinkel: If you know how to use it then you are productive. – Max Toro Oct 13 '11 at 18:19
  • 2
    @MaxToro Your comment logically must be true, i.e. *"If you know how to perform brain surgery than you can operate on someone's brain."* And your assertion is stated in a vacuum; can it be *as* productive as in another language? My experience with it after trying for a 6 months on a failed project is *"no."* The issue with XSLT is that you cannot encapsulate functionality, test it and then know it will work. Coding with XSLT, like CSS requires your code to be specific to the full context of the data and thus its difficult grows exponentially as the complexity of the input XML grows. – MikeSchinkel Oct 14 '11 at 02:37
  • 1
    @MikeSchinkel My point is it depends on the person using it, you cannot compare the productivity of languages, you compare the productivity of people. *"The issue with XSLT is that you cannot encapsulate functionality, test it and then know it will work."* Of course you can. *"Coding with XSLT, like CSS requires your code to be specific to the full context of the data and thus its difficult grows exponentially as the complexity of the input XML grows."* Just because there's a problem you don't know how to solve doesn't mean there's no solution for it. – Max Toro Oct 14 '11 at 15:14
  • @MaxToro We'll have to agree to disagree. – MikeSchinkel Oct 18 '11 at 07:21
  • I've learnt XSLT in the past, and it was not a productive experience. I agree with what @MikeSchinkel says, it's not testable, can't be properly encapsulated (I tried), and the ammount of clutter and boilerplate is enormous. Before I tried, I had hopes, because it seemed like a very good idea. That hope completely vanished after I tried actually using it. And I'm not saying the concept is bad - maybe the newer version of XSL is so much better. – Camilo Martin Sep 13 '12 at 00:30
4

At work, a project I'm on uses XSLT and to be honest, it's a real pain. The actual XSLT files aren't that difficult to work with, but having to create XML adds an extra layer of complexity. I've also found that beyond the most basic pages, the XML tends to get very bloated and messy. So, no, I wouldn't recommend it.

Philip Morton
  • 129,733
  • 38
  • 88
  • 97
3

I know few big web portals which work using XSLT a lot, here in Poland. They used because it can minimize the amount of data sent over the network.

I also worked on the project (Huge HRM application) and we used it there to transform our programming language to .NET.

I would say it is sometimes very useful.

pkolodziej
  • 1,347
  • 3
  • 17
  • 24
  • 2
    +1 for the comment about data minimisation. If you're outputting huge tables of data (paging aside) you can send it in XML very compactly and transform it at the far end, or you can work out your transforms locally and then send several times the quantity of HTML. And it's surprisingly cross-platform, being one of the things that IE has had in for ages. – ijw Jul 08 '09 at 00:18
2

xslt is hard?

It's a programmers job to tackle complex problems and complex standards. There's stuff that is way harder and still needed. Just keep going at it and get's easier each time you need to learn new stuff.

Xslt is easy.

Really! There are good books out there that teach you xslt. Just learn e.g. rdf/owl (a w3c standard) and it can still get much more complex...

xslt is slow? Just use the right caching if you can. (ok, its not always possible...).

Just read about REST (some book or Roy Fielding dissertation) that's essential stuff too.

Now with XProc (xslt piplines) and a small restserver around calabash (Xproc implementaion) you can archive so much. it can definitly save you time. any data can be exportet to XML, made aviliable via REST and transformed with XProc.

st.
  • 156
  • 1
  • 6
2

Symphony CMS uses XSLT. While using that CMS I found that the only real problems I had were to do with learning the XSL/XPath syntax, mostly due to a lack of good tutorials/documentation. Might be worth giving Symphony a try if you want to see some relatively modern XSLT usage.

robotmay
  • 1,318
  • 14
  • 22
2

XSLT is just one method of templating. It is also just one piece of a complete MVC framework, where templating being the View component. XSLT is a great technology, but it's slow and not a first choice on building a scalable web site.

Research on MVC frameworks to see which one fits you best. e.g. ASP.NET MVC, Ruby on Rails, CakePHP, Catalyst, etc.

spoulson
  • 21,335
  • 15
  • 77
  • 102
2

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

Er, what? There are many free and open-source CMSs.

What spoulson said above about templating is the point. Providing output pages from input XML files is fine. But that doesn't get you a CMS. What about C.R.U.D.? Search? Page listings?

If your site is so small that all the relevant updating can be done by you hand-editing some XML files, then why not, go for it. But if it's that simple you might as well just edit HTML by hand.

AmbroseChapel
  • 11,957
  • 7
  • 46
  • 68
2

I like the idea. XSL is a fantastic tool, but you have to have that special moment of enlightenment before you realise how useful it really is. Before that it just seems so-so.

I have used XSL in a variety of applications and it has saved me a lot of time. But obviously dont just use it for the sake of it.

Magnus Smith
  • 5,895
  • 7
  • 43
  • 64
2

What you are describing already exists and is Apache Cocoon: http://cocoon.apache.org/

Bambax
  • 2,920
  • 6
  • 34
  • 43
1

If your platform is ASP.NET check out myxsl

XSLT gives you the ability to do unobtrusive templating, which is IMO the ultimate kind of templating.

Max Toro
  • 28,282
  • 11
  • 76
  • 114
1

As a side note, wowarmory.com is a good example of a high traffic site that uses XSLT. In fact, I think the whole site uses it.

Justin Johnson
  • 30,978
  • 7
  • 65
  • 89
1

Take a look at http://www.umbraco.org/ It is a free open source CMS tool that uses XSLT extensively to generate pages.

To all those who claim XSLT is hard I would say that it is no harder than SQL. There are scenario's that are hard such as grouping, just like in SQL trees are hard.

Pick the right tool for the right job and you shouldn't have any problems.

Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
0

Sounds like a bad idea to me. It's much easier to use something like ASP.NET with the content stored in a database - you can then update the content directly into the database - which in itself will be easier than editing the XML.

cyberbobcat
  • 1,169
  • 1
  • 18
  • 34