1. Home
  2. Computing & Technology
  3. Web Design / HTML

XSL: The Style of XML

Understanding Extensible Stylesheet Language (XSL)

By Jennifer Kyrnin, About.com

In order to explain XSL, you need to know a little about XML. The greatest flexibility of XML is that it has no rules for display. It is all content oriented. However, this strength means that there needs to be style information included in an XML document. This can be HTML or style sheets, or XSL (eXtensible Stylesheet Language).

Updated: October 2003 XSL has changed a bit from when this article was first written. Now it is not specifically a way to define styles on a document, but rather to transform documents from one type of XML to another.

XSL was designed to be used with XML. It provides the formatting information for the context information provided bye XML and the actual content within the document. For example:

If you see a name in an HTML document Jennifer Kyrnin you may (or may not) know that it's a name, but you wouldn't know what it signified. Is it the author, the artist, a reference, or what? Using XML you can specify exactly what that name is:
<authorname>
<first>Jennifer</first>
<last>Kyrnin</last>
</authorname>

With XML the name has been defined so that the parser knows what it is. However, with the above XML you have no display information.

XSL brings this style (or display) information to XML.

XSL stylesheets are XML documents. Let me say that again, XSL stylesheets are XML documents. They follow the same rules, require DTDs and act in similar ways. XSL is one of the first applications that was written with XML. They consist of 5 major components:

  1. construction rules
    <rule>
    These locate elements in the document with defined patterns and results or actions.

  2. style rules
    <style-rule>
    These assign characteristics to elements in the source document.

  3. named styles
    <define-style>
    These define a name for a collection of characteristics.

  4. macros
    <define-macro>
    These define an object with clear parameters.

  5. scripts
    <define-script>
    These calculate results for use in a style attachment.

So, if you want to define style information for the author element, you would write:<rule>
<target-element type="author">
<div font-weight="bold" font-size="8pt" color="#003300">
<children/>
</rule>

<target-element type="author"> is the pattern of the rule. And, <div font-weight="bold" font-size="8pt" color="#003300"> and <children/> are the actions of the rule.

This would tell the parser to display the author element in bold, 8 point type, and green color.

If you then included a <target-element/> with no defined type, it would become the default style for the entire document: <rule>
<target-element/>
<div font-size="12pt" color="#000000">
<children/>
</div>
</rule>

XSL gives a lot of control over documents. XML gives your information machine parseable content, and XSL provides machine parseable formatting information.

Previous Features

Explore Web Design / HTML

More from About.com

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. About.com Web Design A to Z
  5. Web Design Articles R-Z
  6. Web Design/HTML Articles X
  7. XSL: The Style of XML

©2008 About.com, a part of The New York Times Company.

All rights reserved.