|
Introduction to
XSL
XSL, the style
sheet language of XML is far more sophisticated than CSS.
CSS - The
Style Sheet of HTML
Because HTML
uses predefined tags, the meanings of these tags are well
understood: The <p> element defines a paragraph and the <h1>
element defines a heading, and the browser knows how to display
these elements.
Adding display
style characteristics to HTML elements with CSS is a simple
process. Telling the browser to display each element using a
special font or color, is easy to do and easy for a browser to
understand.
XSL - The
Style Sheet of XML
Because XML
does not use predefined tags (we can use any tags we want), the
meanings of these tags are not understood: <table> could mean an
HTML table or maybe a piece of furniture. Because of the nature
of XML, the browser does not know how to display an XML
document.
In order to
display XML documents, it is necessary to have a mechanism to
describe how the document should be displayed. One of these
mechanisms is CSS, but XSL (the eXtensible Stylesheet Language)
is the preferred style sheet language of XML, and XSL is far
more sophisticated than the CSS used by HTML.
XSL - More
than a Style Sheet
XSL consists of
three parts:
- a
method for transforming XML documents
- a
method for defining XML parts and patterns
- a
method for formatting XML documents
If you don't
understand the meaning of this, think of XSL as a language that
can transform XML into HTML, a language that can filter and sort
XML data, a language that can address parts of an XML document,
a language that can format XML data based on the data value,
like displaying negative numbers in red, and a language that can
output XML data to different devices, like screen, paper or
voice.
XSL
Languages
XSL actually
consists of three languages. The most important is XSLT.
XSL is Three
Languages
XSL actually
consists of three languages:
- XSLT is a
language to transform XML
- XPath is a
language to define XML parts or patterns
- XSL
Formatting Objects is a language to define XML display
XSLT is a
language for transforming XML documents into other types of
documents, or into other XML documents.
XPath is a
language for addressing parts of an XML document. XPath was
designed to be used by XSLT.Formatting is the process of turning
the result of an XSL transformation into a suitable output form
for a reader or listener.
XSLT - XSL
Transformations
XSLT is the
most important part of the XSL Standard. It is the part of XSL
that is used to transform an XML document into another XML
document, or another type of document.
XSLT can be
used to transform an XML document into a format that is
recognizable to a browser. One such format is HTML. Normally
XSLT does this by transforming each XML element into an HTML
element.
XSLT can also
add completely new elements into the output file, or remove
elements. It can rearrange and sort the elements, and test and
make decisions about which elements to display, and a lot more.
A common way to
describe the transformation process is to say that XSL uses XSLT
to transform an XML source tree into an XML result tree (or an
XML source document into an XML result document)
How does it
work?
In the
transformation process, XSLT uses XPath to define parts of the
source document that match one or more predefined templates.
When a match is found, XSLT will transform the matching part of
the source document into the result document. The parts of the
source document that do not match a template will (as a general
rule) end up unmodified in the result.
This
Tutorial will focus on XSLT and XPath
Most of the
chapters in this tutorial will focus on XSLT and XPath. We will
use XSLT to define XML transformations and XPath to define the
matching patterns for the transformations.
Even though XSL
consists of three different parts with three different names, we
will use the general term XSL in this tutorial.
XSL Browsers
Very few
browsers support XSL at the moment.
In this
tutorial we will use Internet Explorer 5.0 to demonstrate XSL.
The Internet
Explorer XML Parser
In order to
process an XML document using XSL, you need an XML parser with
an XSL Engine. Internet Explorer 5.0 is currently the only
widely available browser that contains an XML parser with an XSL
engine.
At the moment,
the example code in this tutorial will only work in Internet
Explorer 5.0 or later.
The Internet
Explorer XSL Engine
XSL in Internet
Explorer 5.0 is not 100% compatible with the latest released W3C
XSL standard.
Internet
Explorer 5 was released before the XSL standard was completely
settled (when the XSL standard was still a W3C Working Draft),
but Microsoft has promised to solve this problem in the next
release.
This is the
standard way from the W3C XSL Recommendation:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
This is the
(incorrect) Internet Explorer way (from the XSL Working Draft):
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/TR/WD-xsl"> |
Internet
Explorer MSXML
MSXML 2.0 is
the name of the XML parser that shipped with IE 5.0.
MSXML 2.5 is
the name of the parser that shipped with Windows 2000.
MSXML 3.0 is
the latest release of the XML parser. It can be downloaded from
Microsoft, and will ship with future versions of Internet
Explorer and Windows.
According to
Microsoft, MSXML 3.0 is 100% compatible with the official W3C
XSL Recommendation:
"MSXML 3.0
offers a significant advancement over MSXML 2.5: server-safe
HTTP access, complete implementation of XSLT and XPath, changes
to SAX (Simple API for XML), higher conformance with W3C
standards, and a number of bug fixes"
For more info:
http://msdn.microsoft.com/xml/general/xmlparser.asp
Page 1
2 3
4 |