tags:

views:

217

answers:

7

I've always thought of XML (and SGML before that) data as the devil's format. I'm of the old database and flat files school. Nonetheless, we are developing a commercially-available web product who's framework is based off of translating/transforming XML data in chains.

As we're interviewing for positions as well talking to potential customers, they love the concept of what it will do but are weary of supporting XSLT long-term. One person even called it the proverbial "dead." Dead like COBOL, Unix, and C or dead like Apple Business BASIC?

Anyway, I'm curious if building a web framework on XSLT is really not cutting edge enough (oddly) for companies. Are there inherent XSLT implementation problems that make this venture something worth reconsidering?

+1  A: 

Nothing really wrong with it...

But depending what you are doing it may not provide you with enough hooks to do what you want.

Keith Nicholas
+2  A: 

If your application relies on transforming XML data then by all means, that's what's XSLT is dedicated for and it does a decent job except that the code can be quite verbose.

I've never really heard complains about problems with SAXON as an XSLT implementation.

Maybe looking into SXML, SXSLT, SXPath et cetera is worth considering though.

As far as XSLT being dead, as I notice it's still climbing and not really past its peak, though I do notice more voices that are starting to see the design flaws in XML, XML used as a data storage format to me is an unusual decision, XML is a good data-presentation format, and especially on the web, it's faaar to verbose to as a container to transmit information too but it does it job to present information.

XML does have what some people would call design flaws though.

Lajla
A common misconception is that XSLT transforms an XML to another XML. In reality, XSLT transforms a tree into another tree and, at least in Java and .Net, you are not limited to XML.
newtover
Well, it transforms an XML tree, as in, a tree where every branch has 1: Unordered attributes with textual values. 2: Children, which are ordered and can be purely textual or other branches again. Together with the namespaces and all that crap.This tree can be represented in text in the usual SGML notation of <bla foo="bar">bla</bla> or for instance as (bla (@(foo "bar")) "bla") (SXML), I'm unaware of XSLT performing effective transformations on any non-XML tree though.
Lajla
+3  A: 

Interesting that SharePoint 2010 has fully empraced XSLT. XSLT has legs...fear not.

walt hodgson
+2  A: 

I've used an in house framework that relied on XSLT to produce all it's HTML (and terrifyingly RTF and other formats too) and that's left me with some fairly strong opinions on the subject.

XSLT is a great language for transforming one XML format into another where both are well defined.

If your source data is XML then it's handy for transforming it into XHTML fragments but when you start to stray into templating engine territory things start to get a bit messy.

As with everything it's just a tool and if you use it for what it's good at it'll work well, if you use it at every opportunity you're probably abusing it and if you use it to generate RTF files you're committing a crime against nature.

Dan Head
You can even use XSLT to transform XML into flat files. CSV/Fixed width... pretty painless.
Matthew Whited
I nearly mentioned CSV as another example of taking it to far. It can be pretty painful if you try it, dealing with escaping values is not an easy task.
Dan Head
+1  A: 
sharky
+1  A: 

XSLT is a set of rules to transform a tree into another tree. To use it effectively, you should think about it that way.

Some benefits of the XSLT for me:

  1. Every HTML coder I can rely on, can write XSLT transformations (I can easily outsource the HTML coding), but there is not a lot of them who can easily deal with ASP.Net controls, Mako templates, Django, JSP, Smarty templates and other engines at the same time.
  2. When used correctly XSLT is self-sufficient. I can provide the HTML coder with an input XML, negotiate about the XSLT processor, and develop XSLT transformations separate from the application itself.
  3. XSLT environment is sandboxed, HTML coder almost can not open a security hole himself.
  4. XSLT is not bound to XML: you can write your own adapter to deliver data to XSLT and register your own output handler. That is not an option for solutions based on libxslt (php, python) though.

But that means, that you should not break the flexibility. I did see environments when complex instances with a lot of side-effects in behaviour were passed to a Saxon transformation and the input tree was used only to initiate the process. There was no way to develop separately from the complex application server, and you had to deploy your stylesheet for 5 minutes just to see if the output is correct.

UPD: Some best-practices of mine:

The main thing, as I said, is to keep XSLT transformation separate. Libxslt+exslt, msxsl+native extensions, etc. should suffice for the transformation. If XSLT is missing some power tools, I prefer to do it in the calling code and pass to the transfromation within the input tree.

The application should build an XML (or a tree) of a predictable (documented) structure. For each page I am interested in:

  1. I generate an XML (or write it manually if it is not yet easy to obtain);
  2. prepare the resulting HTML I am going to obtain as a separate static file;
  3. define an XSLT transformation (from several pages this may be the same).

Then I put everything in a VCS and create a batch file to apply to each XML the corresponding XSL, so that result would overwrite the static HTML files.

Now running svn diff html-folder (or similar) will show me if any transformation broke the HTML, and where exactly. I make changes in XSL, and run the batch again. Once the HTML is the same, I commit.

Each change in XML document structure should lead to updating the corresponding XMLs and XSLTs, so that HTML would stay the same. Each requested change in HTML should lead to the corresponding change in XSLTs. HTML coder can work in isolation and I can see if anything went wrong.

The pages in the application, where I use the XSLT usually accept a GET parameter like showinput=1 to return the bare input tree without an applied transformation, so that I could save it and add to VCS as another special case.

Concering caching, when I need it I usually cache the ready HTML page. Frequently changing parts of pages are loaded with client scripting.

newtover
Can you comment on your development challenges with developing *outside* the app server "...there was no way to develop separately from the complex application server..."
Xepoch
@Xepoch: I am not sure what you are asking: to explain why it wasn't easy to develop in a tightly coupled environment, or about the problems that arise when you develop XSLT separately?
newtover
Well, we want to ease the development pain (how the XSLT framewod side, not the framework programming), curious as to your recommendations on how to best do that. I am a decent architect and a worse programmer (are we ever really good?), XSLT is not my personal strong suit so I value anything that would help in deployment and testing ease. Any "best practice" (I hate that term) you might have :)
Xepoch
@Xepoch: I updated my answer.
newtover
+1  A: 

The popularity of existing XSLT-based Web Content Management Systems such as Umbraco and Symphony (SharePoint's already had a mention here) provides good evidence on the suitability of XSLT for a web framework.

In fact, it was the continued popularity of XSLT (though it does admittedly have a marmite factor) that encouraged me to produce, as my company's first product, a GUI based XSLT batch-processing tool, CoherentWeb. The tool's mainly for XSLT testing but, with a built-in browser, its also used as a light-weight web publishing system itself, hence the name.

If anything, XSLT is on the up. Its good to see established XML solutions companies still adopting it in numbers, for example, MarkLogic are about ready to add XSLT capabilities to their XML database product.

The first public W3C draft for XSLT-2.1 was published a couple of days ago, showing continued interest and investment in XSLT's future.

There are also some useful new open standard extensions for XSLT (and XQuery) such as the EXPath project whose function libraries include extensive HTTP and Zip features.

pgfearo