The Ground Cero Guide to XSL
Henrik Aasted Sorensen
<< IntroductionIntroducing the Extensible Stylesheet Language (XSL) >>
2. Short introduction to XML
XML is an abbreviation for eXtensible Markup Language. A markup language is (simply described) a collection of tags and text-values. The most well-known markup language today is HTML, which is used to layout homepages.
XML enables people to design their own markup languages, tailored for storing any kind of information.
The following is an example XML-document:
<addresses>
    <person name="John Doe">
        <address>
            <street> Oakroad 5 </street>
            <city> Lyngby </city>
            <country> Denmark </country>            
        </address>
        <phone> 124-21424-21 </phone>
        <email> jd@example.com </email>
        <category>friend</category>
        <category>co-worker</category>
    </person>
</addresses>
Looking at this document quickly reveals its purpose: it's a markup-language for storing adresses.
Let's take a detailed view of one of the tags:
<person name="John Doe"> ... </person>
<person> is called the opening tag.
name="John Doe" inside the opening tag is called an attribute. The name of the attribute is name, and the value is John Doe.
... Is the contents of the tag. This can be either more tags or text-data.
</person> is the closing tag.
A tag must always be closed to make well-formed XML-document. If a tag doesn't have any contents, it's not necessary to put up both an opening- and and closing-tag. <person/> is the same as writing <person></person>.
Comments in a XML-document have the same syntax as in a HTML-document: <!-- Comment goes here. -->
It's important to notice the structure of a XML-document. The outermost tag, the one containing all the other tags, is called the root-node. In the above example <addresses> is the root node. Any tags in the contents of another tag is called the children of the tag. A XML-document can be visualized like this:
Each black dot is a tag. The top dot is the root-tag. This kind of structure is usually called a tree, because it has a root, which is on top just like a ... and... uh... It's a tree! The black dots are called nodes. Notice that all nodes, except the root, have one and only one parent. Knowing this way of visualizing a XML-document is very important once we start navigating it.
All XML-documents should start with the line
<?xml version="1.0" encoding="iso-8859-1"?>
Variations can be made to the encoding-attribute, but this will not be covered here.
Adding the line
<?xml-stylesheet href="stylesheet.xsl" type="text/xsl"?>
will tell whatever program that wants to render the XML-file, which XSL-stylesheet to use. Making XML-documents that contain this line will make it possible for Internet Explorer (versions 6 and above) to render the document according to the stylesheet. This is a simple and very effective way of trying out the examples in this tutorial.
These are the very basics of writing XML. So far it may not seem like much ... and truth be told it isn't. :) What makes XML powerful and useful is the tools that can be used in connection with it. This tutorial will focus on the XML-language XSL and its applications.
<< IntroductionIntroducing the Extensible Stylesheet Language (XSL) >>
Index