Adding a Bunch of Style: XSL Advantages
July 19, 1999
Are you wondering what is the point in bothering with
XSL
if you can use the much simpler CSS
to render XML documents? There are several limitations in using
CSS:
- Rendering is dependent on the browser's support of CSS.
- You can only assign styles to elements; attributes are
completely ignored.
- You can process each input element only once.
- You can't add elements or other content to the output.
- You can't do conditional processing.
XSL has none of these limitations, except the first. And that
is the reason for excitement about XSL. XSL can transform its
input into something very different for output, if
so desired. In can be used to generate headers/footers, page
numbering, sorting, filtering, and otherwise process the input.
The advantages of XSL (XSLT and XSL-FO) include:
- You don't need a browser; can use server side processing
and deliver HTML to the client.
- You can process elements, attributes, and content.
- You can add elements and content to output.
- You can sort or filter output; the result can be output in
any language.
(For example, you could generate compilable Java code based
on XML content, as IBM has done.)
- You can do conditional processing (decision and switch-like
statements).
- You can use canned or user-defined functions.
- You can achieve complicated, desktop publishing page layouts
and styles (eventually).
As was the case with referencing a CSS file, we simply add a
reference to the XSL stylesheet after the prolog in the XML
document:
<?xml-stylesheet type="text/xsl" href="collection2.xsl"?>
Note, however, that an XSL document is actually another XML
document! It must follow the rules of well-formed XML. XSL
also has its own complicated syntax which will be covered
in detail in subsequent WDVL articles.
Viewing It With IE5 and Mozilla, Take 3 (CSS)
Doing It With XML, Part 2
Viewing It With IE5 and Mozilla, Take 4 (XSL)
|