Question

What's the difference between XSLT and XSL-FO ?

Every resource I've read deal with them as if they were 1, or at least very closely tied..

Was it helpful?

Solution

I was wondering about the basis of the question because I thought it was easy to answer, however as soon as you go here: http://www.w3.org/TR/xsl/ it becomes clear that its actually a good question - because pretty much the first thing on the page is this statement:

This specification defines the features and syntax for the Extensible Stylesheet Language (XSL), a language for expressing stylesheets. It consists of two parts:

  1. a language for transforming XML documents (XSLT), and
  2. an XML vocabulary for specifying formatting semantics.

However, back in the real world, XSLT (which is also what most people will assume you mean by XSL) is a means for transforming XML documents into something else - that something else more often than not being another well structured document probably also formatted as XML (though I've used XSLT to render XML to csv and plain(ish) text).

XSL-FO on the other hand is about formatting - about laying out content on a page or a sequence of pages in a fairly strict fashion. Its useful because it allows you to manage content that is spread across multiple pages, its relatively straightforward to specify the format of a page (or even and odd pages) including headers, footers, borders, columns, etc and have your content flow into that. One would therefore take a load of data in, say, an XML format and then use XSLT to convert that data into a document consisting of XSL-FO that in turn is rendered using an appropriate tool in say PDF for print or other means of distribution.

The use case I have is to take a pile of tabular data, export that data as XML, render that into XSL-FO and from there to PDF which goes to a printer who turns said PDF into a 500 page directory. One specifies in the XSL-FO that one wants page numbers, page breaks in specific circumstances, that there is a table of contents and an index (each based on particular elements) and the rendering process (to PDF) handles filling in the page numbers across the board.

Hopefully you're a bit less confused now..

OTHER TIPS

Aside from the similarities in the acronyms the two technologies used to be part of the same W3C spec(in draft form). It was later decided to split XSL(XSL-fo) and XSLT out into two separate specifications.

Quote from W3Schools:

XSL-FO is Formally Named XSL

Why this confusion? Is XSL-FO and XSL the same thing?

Yes it is, but we will give you an explanation:

Styling is both about transforming and formatting information. When the World Wide Web Consortium (W3C) made their first XSL Working Draft, it contained the language syntax for both transforming and formatting XML documents.

Later, the Working Group at W3C split the original draft into separate Recommendations:

* XSLT, a language for transforming XML documents
* XSL or XSL-FO, a language for formatting XML documents
* XPath, a language for navigating in XML documents

A detailed annotation of the chronology can be found on Dave Pawson's Home page: http://www.dpawson.co.uk/xsl/sect1/history.html

XSL is family of languages used to transform and render XML documents

XSLT(XSL Transformations) : is a language for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or into XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, PostScript and PNG.

Transformation can do the following three ways:

  1. Referenced: Let the browser do the transformation : using <xsl:processing-instruction>
  2. Embedded: Client side transformation using JavaScript.
  3. Runtime: To make XML data available to all kind of browsers, we can transform the XML document on the SERVER.

For example:

enter image description here XSL-FO(XSL Formatting Objects) : is not supported by web browsers because it's designed for print output, not online viewing. (from @Hobbes)
Output formats currently supported include PDF, PCL, PS, AFP, TIFF, PNG, SVG, XML (area tree representation), Print, AWT and TXT. The primary output target is PDF. Soruce

Example code:

<fo:table-row height=".5cm">
            <fo:table-cell>
                <fo:block></fo:block>
            </fo:table-cell>
        </fo:table-row>

Flow chart: enter image description here

XSLT is used for transforming, XSL (which is the same as XSL-FO) is used for formatting.

http://www.w3schools.com/xslfo/xslfo_intro.asp

What about the Wikipedia definition?

XSL Formatting Objects, or XSL-FO, is a markup language for XML document formatting which is most often used to generate PDFs. XSL-FO is part of XSL, a set of W3C technologies designed for the transformation and formatting of XML data. The other parts of XSL are XSLT and XPath. As of December 12, 2006, the current version of XSL-FO is v1.1.

This can be quite confusing as w3schools tutorial site (not related to w3.org) says

XSL-FO is now formally named XSL

enter image description here

that means XSL-FO and XSL is the same thing but they are not!

XSL is basically representing XML data into an HTML document XSL-FO is about formatting of the document itself. For example if you want to transform XML into a word document, you want to add page numbers, change margin or page layout, add headers and footers etc. These items can only be addressed via XSL FO tags, XSLT has no way to access the document properites. In technical field, you will most likely come across scenario where XML data is rendered in word or PDF document. It would need page numbers, layout format, header etc. These are very important part of the document.

Another big difference is XSL and XSL FO has different engines. XSL can not render XSL-FO tags. This question talks about which engine to use for XSL FO

Which is the Best commercial xsl fo engine?

A typical XSL Fo tempate lools like this

<?xml version="1.0" encoding="ISO-8859-1"?>

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

<fo:layout-master-set>
  <fo:simple-page-master master-name="A4">
    <fo:region-body />
  </fo:simple-page-master>
</fo:layout-master-set>

<fo:page-sequence master-reference="A4">
  <fo:flow flow-name="xsl-region-body">
    <fo:block>Hello W3Schools</fo:block>
  </fo:flow>
</fo:page-sequence>

</fo:root> 

Notice that there is no reference to XML data. It is all about formatting the document itself. This is an extremely important element when it comes to transforming XML data into legal documents. Because you need pager number, document number, layout etc if the output document is pdf or word. With out this information, it is painfully hard to implement page numbers or headers etc.

The confusion comes in because this document will almost certainly contain XSL tags as we will pulling XML data. However if there is no XSL Fo engine, the document will not be rendered.

So in short they are similar and work together but they are not the same thing. They are rendered by different engines.

Like so many other things, it depends on your point of view and your history.

XSLT is a language (written in XML) "for transforming XML documents into other XML documents.", although the current XSLT 3.0 CR (http://www.w3.org/TR/xslt-30/) changes that to "a language designed primarily for transforming XML documents into other XML documents." (Emphasis added.)

XSL-FO is "an XML vocabulary for specifying formatting semantics." It is defined in the "Extensible Stylesheet Language (XSL) Version 1.1" Recommendation (http://www.w3.org/TR/xsl11/). A formatter, such as from Antenna House, takes an XML document in the FO vocabulary and produces styled and paginated output.

Where the history comes into it is that initially there was only one spec -- Extensible Stylesheet Language (XSL) -- that defined both transformation -- getting your XML into the FO XML vocabulary -- and styling -- getting the FO into styled and paginated form. The history page from Dave Pawson (http://www.dpawson.co.uk/xsl/sect1/history.html) linked to from Mads Hansen's answer has the full details, but along the way to XSL becoming a Recommendation, the transformation part was seen to be generally useful and was broken out as "XSL Transformations (XSLT)". Transforming markup to markup wasn't new, but having a standard for it with multiple, (mostly) compatible implementations was a breath of fresh air.

The way that XSLT could address parts of an XML document was also seen to be generally useful, and it was broken out as "XML Path Language (XPath)" so it could be used by other specs. (XPath is used by, e.g., XQuery and XLink.)

Where the point of view comes into it is that the XSL 1.1 Recommendation still defines a process of transformation plus formatting, but the transformation part just happens to be defined in a separate document. See http://www.w3.org/TR/xsl11/#d0e386

While the official XSL 1.1 PoV is that XSLT and XSL-FO are both parts of XSL, and probably every FO formatter can do the transformation part, in practice, most people transform their XML into XML in the FO vocabulary using an external XSLT processor and feed that FO XML to their formatter.

Where history meets point of view is that XSLT 1.0 (http://www.w3.org/TR/xslt) defined itself as being part of an XSL system:

XSLT is designed for use as part of XSL, which is a stylesheet language for XML. In addition to XSLT, XSL includes an XML vocabulary for specifying formatting. XSL specifies the styling of an XML document by using XSLT to describe how the document is transformed into another XML document that uses the formatting vocabulary.

But that point of view isn't present in XSLT 2.0 (http://www.w3.org/TR/xslt20/) and is long gone by the time of XSLT 3.0.

The final part of point of view is that when many people say "XSL" they mean just XSLT, except for those that when they say "XSL" they mean XSL-FO while mostly forgetting that their FO formatter can do both.

XSL-FO stands for Extensible Stylesheet Language Formatting Objects and is about formatting and now is known as XSL to avoid all confusion. So do not worry about XSL-FO anymore.

XSLT however is about transforming xML. So it is very clear. XSL is about formatting and XSLT is about transforming.

XSLT is a template format that can be used to generate all sorts of documents, including plain text documnent.

XSL-FO denotes the use of XSLT to produce FO documents.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top