XML: CSS and XSL

I think everyone heard about XML that stands for Extensible Markup Language.

So XML is Just Like HTML?

No. In HTML, both the tag semantics and the tag set are fixed. An <h1> is always a first level heading and the tag is meaningless. The W3C, in conjunction with browser vendors and the WWW community, is constantly working to extend the definition of HTML to allow new tags to keep pace with changing technology and to bring variations in presentation (stylesheets) to the Web. (xml.com)

XML specifies neither semantics nor a tag set. In fact XML is really a meta-language for describing markup languages. In other words, XML provides a facility to define tags and the structural relationships between them. Since there's no predefined tag set, there can't be any preconceived semantics. All of the semantics of an XML document will either be defined by the applications that process them or by stylesheets. (xml.com)

XML documents just contain tags defined by anybody and data. If you have a XML document, and if you want to show with a browser; you are going to need to add some display information. How? There must be some options.

  • Displaying XML with CSS
  • Displaying XML with XSL
  • XML in Data Islands
  • XML Parser

If someone knows CSS, I think s/he directly will choose CSS. What about XSL (eXtensible StyleSheet Language)!

With CSS (Cascading Style Sheets) you can add display information to an XML document. Would you use CSS to format your future XML files? No, we don't think so!

We DO NOT believe that formatting XML with CSS is the future of the Web. Even if it looks right to use CSS this way, we DO believe that formatting with XSL will be the new standard (as soon as all main browsers support it). (w3schools.com)

With XSL you can add display information to your XML document. XSL is the preferred style sheet language of XML. XSL is far more sophisticated than CSS. (w3schools.com)

I have seen some discussions are going about CSS and XSL on at xml.com.

Also there are some other explenations at W3C:

How is XSL different from CSS?

XSL uses a XML notation, CSS uses its own. In CSS, the formatting object tree is almost the same as the source tree, and inheritance of formatting properties is on the source tree. In XSL, the formatting object tree can be radically different from the source tree, and inheritance of formatting properties is on the formatting object tree.

Aside from these technical differences, mature implementations of CSS1 and (parts of) CSS2 are available, whilst XSL is currently too new to have mature browser and content-authoring support.

Will XSL replace CSS?

No. They are likely to co-exist since they meet different needs. XSL is intended for complex formatting where the content of the document might be displayed in multiple places; for example the text of a heading might also appear in a dynamically generated table of contents. CSS is intended for dynamic formatting of online documents for multiple media; its strictly declarative nature limits its capabilities but also makes it efficient and easy to generate and modify in the content-generation workflow. So they are two different tools; for some tasks, CSS is the appropriate choice and for some tasks, XSL. They can also be used together - use XSL on the server to condense or customize some XML data into a simpler XML document, then use CSS to style it on the client. (w3.org)

So what do you think about XSL and CSS?

One Response to “XML: CSS and XSL”

  1. Joseph Yi Says:

    XSL should be limited in usage to transform XML to another DTD/schema/format (i.e. HTML, FOP, CSV), and in the case of HTML, I recommend that nothing be defined in terms of layout/style since that is what CSS is for. There are browser compatibility issues doing client side XSL transforms so neither serve as magic bullets. However, having used both technologies for many years, the best solution is to perform server side XML/XSL transformations and render HTML that will use CSS. You should check out http://www.csszengarden.com/ for a proof of concept example (if you haven’t already, anyway). In theory, the HTML they use could have been XML transformed by an XSL stylesheet. Anyway, I’d recommend using XSL sparingly in general. Isolate what you consider as ‘data’ that you anticipate requiring multiple data formats and use CSS liberally for HTML layout and style. They should be viewed as complimentary technologies, not competing.

Leave a Reply