0

After researching XSLT for some time, I can imagine that, as with any other technology, it can do certain things very well, but would not be suitable in other instances. However I haven't been able to find too many stand-out applications.

Why choose an XSL-transformation? Seems to have a lot of posts about general pros and cons in certain areas, but the question is more centered on producing HTML for a front-end. What are some of the other applications of XSLT? Preferably applications of XSLT that it excels in. (A use of XSLT that may not be naturally apparent would also be a plus)

Some apparent strengths of XSLT seem to be (and correct me if I'm wrong in it being a strength):

  • Transforming an XML document into a PDF document
  • Changing the structure of one XML document on the fly so that it matches the structure of another
  • Handling many different templates for view on different devices
  • Transform an XML document into an import file for a database
Community
  • 1
  • 1
richard008
  • 403
  • 7
  • 15
  • At my last position they used XSLT heavily to transform XML to HTML. This works great about 10 years ago, now if you have a ASP.net MVC platform there is no reason to do this. – cgatian May 07 '13 at 17:15
  • Use XSL for transforming XML into other XML, especially mixed-content XML or where the input and output are similar. For anything else there are probably better tools. – Francis Avila May 07 '13 at 17:16
  • possible duplicate of [XSLT good choice for web framework?](http://stackoverflow.com/questions/2854583/xslt-good-choice-for-web-framework) – newtover May 07 '13 at 17:21
  • http://www.onenaught.com/posts/8/xslt-in-server-side-web-frameworks – Max Toro May 14 '13 at 02:28

2 Answers2

3

These are the strengths that lead me to use XSLT for most programs I write; your situation may vary.

1 More comfortable handling of XML

Because XSLT was designed from the ground up for processing XML data, some people find that it has a lower impedance mismatch for XML than most conventional programming languages; this is also true for XQuery. Given sanely designed XML input, it is often (some would say almost always) easier to process it (for whatever purpose) using XSLT than using another language. Many serious users of XML would, I suspect, generalize your list of XSLT's strengths in that spirit and prefer XSLT (or XQuery) whenever the input data are in XML. Generating XML is also easy in XSLT, whereas many programmers working in other languages appear to find the process of generating well formed XML error-prone.

2 Declarative, functional language

XSLT is a declarative, functional language, and shares many of the strengths of languages in that class. Some programmers oriented toward procedural languages find it hard to grok precisely because it is declarative and functional; it is not uncommon for non-programmers to find XSLT easier to learn than programmers coming from C or Java. (Some programmers appear to find this a threatening experience, which may explain some of the animus they show to XSLT and XML.)

3 XML syntax

Because XSLT stylesheets are written in XML, it is easy for any good off-the-shelf XML editor to provide excellent syntax guidance; my experience (for what it is worth) is that when writing in XSLT I make almost no syntax errors -- in marked contrast to my experience in other languages --, and when I make a typo it is immediately apparent and immediately correctable.

Some people, of course, like XSLT in general but specifically single out its XML syntax for dislike; it takes all kinds to make a world.

4 Templates and data-driven flow of control

Technically, XSLT is characterized by its use of templates and pattern matching on the input to control the flow of execution. This makes it easier to write XSLT programs that behave robustly in the presence of unexpected input or evolution of the input format, and (coupled with XSLT's rule for calculating template priority between top-level stylesheet and imported stylesheets) easier to write new programs that add small amounts of functionality to existing programs.

XSLT 1.0 is not particularly well suited to handling non-XML data; in XSLT 2.0, it is much easier to do so.

C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65
1

I like XSLT for several reasons:

  • It is a very natural language to manipulate XML
  • Its functional nature makes it a very secure language to manipulate XML
  • Hardware acceleration products like DataPower make it the fastest language to manipulate XML
  • It is truly an open source language
user2379881
  • 83
  • 1
  • 5