|
|
|
|
|
|
|
|
|
|
|
|
• Products & Services
|
|
• Buy software
|
|
|
|
• Downloads
|
|
• Support
|
|
|
|
• Customer testimonials
|
|
• FAQ
|
|
|
|
• Free newsletter
|
|
• Press
|
|
|
|
• Mailpiece-design site
|
|
• Links
|
|
|
|
• News archives
|
|
• Contact
|
|
|
|
• About
|
|
• Home
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XML BUZZWORDS:
XQL stands for
"XML Query Language."
It is a language
that allows XML
document formats to
represent database queries.
Click here to learn more.
XPath stands for
"XML Path Language."
It is a specification
that defines how
a specific item in an
XML document can
be located.
Click here to learn more.
XHTML Stands for
"Extensible Hypertext
Markup Language."
This is a
reformulation of HTML
as XML. You can
think of XHTML as a
"cleaned up"
form of HTML. XHTML
looks pretty much
like "regular"
HTML, but — unlike
"regular" HTML —
XHTML has a rigid and
predictable structure, so
computer programs can
parse XHTML more easily
than they can parse HTML.
Click here to learn more.
XSLT (aka XSL-T)
stands for
"Extensible Stylesheet
Language Transformation."
XSLT is the process
of "merging" XML
code and XSL code
together to produce
some other kind of
code. Typically, the
code that is
produced is HTML
code - but the XSLT
process can produce
many other kinds of code.
Click here to learn more.
XForms is the
W3C's name for the
next generation of
Web forms. Learn
about XForms at
Click here to learn more.
XLink stands for
"XML Linking
Language."
It is also known as "XLL."
XLink allows elements
to be inserted into XML
documents in order to
create and describe
links between resources.
Click here to learn more.
XPointer stands for
"XML Pointer
Language."
XPointer supports
addressing into
the internal
structures of
XML documents. It
allows for
examination of a
document's
hierarchical structure
and choice of its
internal parts based
on various properties,
such as element
types, attribute
values, character
content, and relative
position.
Click here to learn more.
XSL-FO stands for
"XSL-Formatting Objects."
XSL-FO is an
XML-based method for
describing how pages
of text and graphics
will look. With XSL-FO,
you can exercise very
tight control over the
layout of your text and
graphics; thus, XSL-FO
is good for creating
printed documents from
XML information. (Note
that - in the examples
here on our Web page -
we use XSL without
FO to create HTML
documents for Web
display. Using methods
such as those that we
show in our examples,
you can create HTML
code that displays XML
information in an
attractive and
functional manner in a
Web browser — but this
HTML code is not well
suited for creating
printed documents.)
The main concept here
is this: if you had some
information in XML
format, and you needed
to display it on the Web
and you also needed to
print it in the form of a
book, you'd write an
XSL style sheet that
uses formatting objects
(FO) to lay out the
printed book; and you'd
write a different XSL
style sheet (one that
doesn't use formatting
objects) to display the
same information
on the Web.
Generally, using
XSL-FO technology to
generate code that is
used for printing a
paper document is a
two-step process. In
the first step, you use
XSL to transform an
XML document into a
new XML document
that uses the XML-FO
vocabulary. In the
second step, you use
special software to
transform the XML-FO
document into a final
format (for example, PDF).
Click here to learn
more about XSL-FO.
FOP is a
Java program that
converts XSL-FO
files to PDF format.
Click here to learn more.
PI stands for
"Processing Instruction."
A PI is a command
contained in XML code
that is to be
carried out by a
program that uses the
XML code. The following
line of code is a PI:
<?xml version='1.0' ?>
(Note that this line of code
is included in some of the
examples that we show on
this Web page.)
Web Services
are applications
that can describes
themselves to other
applications on the
Web and can be invoked
by other applications
across the Web.
Click here to learn more.
SVG stands for
"Scalable Vector Graphics."
SVG is an XML-based
language for describing
two-dimensional graphics.
Click here to learn some
basic concepts about SVG.
Click here for detailed
information about SVG.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QUESTION: What is XML, and how does it work?
ANSWER: "XML" stands for "Extensible Markup
Language. You can think of XML as a method for describing
information so that computers (and humans) can understand it easily.
In this Web page, we'll discuss some basic XML concepts. We'll also
give some examples that show how XML technology works, and we'll
talk about the software that you'll need if you are a developer who
will be working with XML technology.
To start learning about XML, you can just
scroll down the page and start reading,
or you can click on specific topics below.
|
|
|
Here is some XML code:
<?xml version='1.0' ?>
<students>
<student>
<name>
<first>John</first>
<middle>Michael</middle>
<last>Green</last>
</name>
<birth_date>
<month>8</month>
<day>28</day>
<year>1992</year>
</birth_date>
<sex>male</sex>
<grade>3</grade>
</student>
<student>
<name>
<first>Jane</first>
<middle>Marie</middle>
<last>Boyd</last>
</name>
<birth_date>
<month>2</month>
<day>26</day>
<year>1993</year>
</birth_date>
<sex>female</sex>
<grade>2</grade>
</student>
<student>
<name>
<first>Nancy</first>
<middle>Elizabeth</middle>
<last>Butterworth</last>
</name>
<birth_date>
<month>4</month>
<day>05</day>
<year>1993</year>
</birth_date>
<sex>female</sex>
<grade>2</grade>
</student>
</students>
You can probably understand this information quite easily
after looking at it for a few moments. Let's break it down.
- The line that says <?xml version='1.0' ?>
tells computer programs and humans that are reading the file that it is an
XML file and that the XML code in the file conforms
to Version 1.0 of the XML Specification.
- The portion of the XML code
that contains data begins with
<students> and ends with
</students>. You
can assume that the file contains information about
(duh!) students!
- The code is sectioned off into areas that begin with
<student> and end with
</student>. Each of these sections gives
information about a particular student.
- For each student, each individual tidbit
of information is enclosed within a set of labels. For
example, the student's grade is preceded by <grade>
and followed by </grade>.
|
Technically speaking, XML is not a language.
(Yes, we know we just told you that
"XML" stands for "Extensible Markup
Language" — and now we are saying that XML isn't
even a language! We're sorry that this is somewhat confusing,
but that's just the way it is. Bear with us, and we will
explain...)
|
XML is a
set of
rules that explain how to create languages.
Stretching this definition a bit, some people say that "XML is
a language that specifies how to create other languages" (which
is why the folks who created XML can get away with calling it
"Extensible Markup Language").
In our discussion here, languages that conform to XML's rules
will be referred to as "XML-based languages."
We will call the above
XML-based language the
"students" language.
|
As we've said, XML is a set of rules that explain how to create languages.
To understand this concept, think for a
moment
about two languages that are probably familiar to
you: English and Spanish. There is a set of
basic syntax rules that apply to both languages, such
as:
- Words are separated from each other by
spaces.
- Words are contained in sentences.
- A sentence begins with a capitalized word
- A sentence ends with
a period, question mark, or exclamation point.
Just as English and Spanish have syntax rules, so does XML. Here are some of them:
- Each piece of information starts and ends with a
label.
- Each label starts with < and ends with
>.
- The label that precedes a piece of information does
not begin with a slash ("/");
the label that follows a piece of
information does begin with a slash.
- Small pieces of information are contained within
larger pieces of information.
All XML-based languages conform to these rules.
|
In XML parlance, the labels that enclose chunks of information are
called "tags." In our example above, "students"
is a tag, "student" is a tag, "name" is a tag,
"first" is a tag, etc.
To specify an hierarchy within a collection of information, you nest tags inside each other.
For example, in the "students" language, <first>, <middle>,
and <last> are nested inside <name> which in turn is nested inside
<student> which in turn is nested inside <students>.
ANOTHER XML-BASED LANGUAGE
Now look at the following XML-based "faculty_members"
language:
<?xml version='1.0' ?>
<faculty_members>
<faculty_member>
<name>
<first>Joanne</first>
<middle>Gayle</middle>
<last>Jones</last>
</name>
<date_of_birth>08/28/1955</date_of_birth>
<gender>female</gender>
<job_title>teacher</job_title>
<salary>42,000</salary>
</faculty_member>
<faculty_member>
<name>
<first>Ruth</first>
<middle>Ann</middle>
<last>Green</last>
</name>
<date_of_birth>08/25/1978</date_of_birth>
<gender>female</gender>
<job_title>teacher's assistant</job_title>
<salary>21,500</salary>
</faculty_member>
<faculty_member>
<name>
<first>Vincent</first>
<middle>John</middle>
<last>Pellio</last>
</name>
<date_of_birth>07/16/1959</date_of_birth>
<gender>male</gender>
<job_title>teacher</job_title>
<salary>36,500</salary>
</faculty_member>
</faculty_members>
Right away, you can see that there are some similarities and
some differences between
the "students" language and the "faculty_members"
language.
The two languages are similar in that they both follow
the XML syntax rules.
However, they are different in a couple of ways.
- First, the two languages use
different terminology for the same types of information. For
example, the "students" language has tags called
"birth_date" and "sex," but the
"faculty_members" language uses tags called
"date_of_birth" and "gender" to express
the same concepts.
- Second, the information is organized differently in the two
languages. In the "students" language, the date of birth
is broken down into three pieces: month, day, and year. In the
"faculty_members" language, however, the date of birth
is expressed as one piece of text.
Going forth with our analogy — let's go over some of the
differences between English and Spanish:
The words themselves are different:
- Here are some English words:
house hello bicycle dove
- Here are the Spanish equivalents:
casa ola bicicleta paloma
The rules of grammar are different:
- In English, an adjective comes before the noun that it modifies:
a white dove
- In Spanish. an adjective comes after the noun that it modifies:
una paloma blanca
To sum up: the differences between two XML-based languages are a lot like
the differences between English and Spanish. That is: the syntax rules are
basically the same, but some of the words are different, and the rules of
grammar are different.
|
* * * TIME TO REVIEW * * *
Before we go on, let's review what we've learned so far
about XML:
- XML is not a language. It is a set of rules that specify how to create a language.
- XML's rules specify the syntax that is used for all XML-based languages.
- XML tags specify the meaning of each individual chunk of information.
- XML tags can be nested to describe hierarchical relationships among chunks of information.
|
To create an XML-based language such as the
"students"
language or the "faculty_members" language, all you
really have to do is
figure out what kind of information is needed; figure out
a logical,
hierarchical structure for the information; and then use
XML rules to put it together.
For example, to create the "students" language, the first thing
we did was think about the characteristics of students. Basically, what we came up with
was this: students have names, each student was born on a certain date and
is either a boy or a girl, each student is assigned to a grade number.
After thinking about the characteristics of students and
after
thinking about the hierarchy that we needed, we were
ready
to create the "students" language, which we did
by
typing the XML code into a text editor. We used a text editor called
"XMLwriter," which is designed specifically for creating XML
files. However, you don't need a special text editor - you can
use pretty much any text editor that you have on your computer.
For example, if you are using a Windows computer, you could use
Notepad, WordPad, or Microsoft Word. Just make sure that you save
your XML files in plain-text (ASCII) format.
We think you'll agree that the XML-based
"students"
language and the XML-based "faculty_members" language
can be understood pretty easily be most
literate,
English-speaking humans.
But what about computers? Can two computers
understand an XML-based language well
enough so that they can use that language
to exchange information?
The answer is: "Yes, but the computers need help
understanding each particular XML-based language."
|
It turns out that are two methods for
describing XML-based languages. They are:
- The Document Type Definition (DTD)
- The XML Schema
In this discussion, we will talk about only one of them: the DTD. Most of
the things that we say about the DTD apply to the XML Schema as well.
|
A DTD is a series of expressions that define the logical structure of
an XML document. In other words, the expressions in a DTD specify the rules for a
particular XML-based language.
Humans and computers use DTDs to understand XML-based languages.
|
Below is a DTD that specifies the rules for the
"faculty_members" language.
(DTD code is not as easy to understand as XML code. Don't be concerned if
you don't understand this DTD code. We are just showing it to you
here to give you a general idea of what a DTD looks like.)
<!ELEMENT faculty_members
(faculty_member+)>
<!ELEMENT faculty_member
(name, date_of_birth, gender, job_title, salary)>
<!ELEMENT name
(first, middle, last)>
<!ELEMENT date_of_birth
(#PCDATA)>
<!ELEMENT gender
(#PCDATA)>
<!ELEMENT job_title
(#PCDATA)>
<!ELEMENT salary
(#PCDATA)>
<!ELEMENT first
(#PCDATA)>
<!ELEMENT middle
(#PCDATA)>
<!ELEMENT last
(#PCDATA)>
DTDs function as "translators"
that enable computer programs to understand particular
XML-based languages. A computer program that is designed for
XML technology
can digest a DTD as easily as a dog digests Alpo. Once
two computer programs have digested
the above DTD, they can talk to each other about faculty_members
for forty days and forty nights or even longer.
As mentioned above, DTDs are also used by humans. For example, when a person
is creating an XML-based language, that person usually creates a DTD that
describes the language. Creating a DTD helps the person
to organize his thoughts while he is creating the XML-based language.
Also, if other people need to understand the language that is being
created, the person creating the language can give the DTD to
the other people - and they can use the DTD to learn the language.
Note that you are not required to create a DTD when you
create an XML-based language. If you are creating a very
simple XML-based language that needs to be understood by humans but does
not need to be understood by computers, there is no need to
create a DTD. In real-life situations, however, XML-based
languages are usually somewhat complicated - and they usually
need to be understood by computers.
|
At this point, it's appropriate to discuss the concepts of "well-formed" XML
and "valid"XML.
Well-formed XML:
"Well-formed" XML is simply XML that is
structured according to XML syntax rules. Here is an XML file that is
well formed.
<?xml version = "1.0" ?>
<Name>
<First>Sally</First>
<Middle>Jessy</Middle>
<Last>Raphael</Last>
</Name>
Here is an XML file that is not well formed, because there is a
syntax error in it (the ">" after "/Middle" is missing).
<?xml version = "1.0" ?>
<Name>
<First>Sally</First>
<Middle>Jessy</Middle
<Last>Raphael</Last>
</Name>
When working with XML, it is essential to make sure that your XML
is well-formed - otherwise, your XML won't work with computer programs
that need to understand it.
You can obtain software programs that will tell
you whether or not your XML is well formed. Such a
program is called an XML Parser. An XML Parser
reads XML code, analyzes it, and puts it into
computer memory. XMLwriter, which we'll talk
about a little later, contains an XML Parser.
Valid XML:
"Valid" XML is XML that adheres to a specific DTD (or a specific XML Schema).
For example, the following XML file is valid with respect to the
DTD that we presented earlier, because the information is structured according to that DTD.
<?xml version = "1.0" ?>
<faculty_members>
<faculty_member>
<name>
<first>Ronald</first>
<middle>George</middle>
<last>Cutler</last>
</name>
<date_of_birth>May 17, 1954</date_of_birth>
<gender>male</gender>
<job_title>teacher</job_title>
<salary>45,700</salary>
</faculty_member>
<faculty_member>
<name>
<first>Frederick</first>
<middle>James</middle>
<last>Adler</last>
</name>
<date_of_birth>March 6, 1958</date_of_birth>
<gender>male</gender>
<job_title>teacher</job_title>
<salary>46,250</salary>
</faculty_member>
<faculty_member>
<name>
<first>Vivian</first>
<middle>Arlene</middle>
<last>Sullivan</last>
</name>
<date_of_birth>September 12, 1959</date_of_birth>
<gender>female</gender>
<job_title>teacher's assistant</job_title>
<salary>22,500</salary>
</faculty_member>
<faculty_members>
Now look at the following XML file. It is not valid with respect to the
DTD that we showed, because it doesn't have any "job_title"
information - and the DTD specifies that "job_title" information
is required.
<?xml version = "1.0" ?>
<faculty_members>
<faculty_member>
<name>
<first>Ronald</first>
<middle>George</middle>
<last>Cutler</last>
</name>
<date_of_birth>May 17, 1954</date_of_birth>
<gender>male</gender>
<salary>45,700</salary>
</faculty_member>
<faculty_member>
<name>
<first>Frederick</first>
<middle>James</middle>
<last>Adler</last>
</name>
<date_of_birth>March 6, 1958</date_of_birth>
<gender>male</gender>
<salary>46,250</salary>
</faculty_member>
<faculty_member>
<name>
<first>Vivian</first>
<middle>Arlene</middle>
<last>Sullivan</last>
</name>
<date_of_birth>September 12, 1959</date_of_birth>
<gender>female</gender>
<salary>22,500</salary>
</faculty_member>
<faculty_members>
The concept of "valid" XML doesn't apply unless you
have a DTD (or XML Schema) for the particular XML-based language that you are working
with. Remember, you are not required to create a DTD or XML Schema when you
create an XML-based language. In real-life situations, however,
there is usually a DTD or an XML Schema; and you should make sure that each XML file
that you create is valid with respect to the DTD or XML Schema on which it is based.
Most XML Parsers have a feature that will tell
you whether or not your XML is valid. XMLwriter, which we mentioned
above, has an XML Parser that is capable of validating XML files.
You tell XMLwriter what XML file you want to validate and what
DTD to validate against, and
XMLwriter tells you whether or not your XML is valid.
Note that XML can be well-formed without being valid.
That is the case with the "faculty_members" example above -
the XML follows all the required syntax rules; but because the
"job_title" information is missing, it doesn't adhere to
the DTD, so it is invalid.
* * * TIME TO REVIEW * * *
Let's do another review:
- XML is not a language. It is a set of rules that
specify how to create a language.
- XML's rules specify the syntax that is used
for all XML-based languages.
- XML tags specify the meanings of individual bits of information and describe
hierarchies within a collection of information.
- A particular XML-based language is described by a DTD or an XML Schema that
was prepared for that specific language.
- Humans and computers use DTDs and XML Schemas to understand XML-based languages.
- You should make sure that all your XML files are well formed, which
means that they are structured according to the syntax rules of XML.
- If you are working with a DTD or an XML Schema, you should also make sure that all your
XML files are valid, which means each XML file follows the rules
that are specified in the associated DTD or XML Schema.
- To see if your XML is well formed and valid, you use a software program
called an XML Parser.
- Remember that XML can be invalid even if it is well formed.
|
Al Gore invented XML while he was inventing the Internet.
(Okay — we're just kidding!)
The real story is that several years ago, some smart, computer-literate folks decided
that the world needed a good, simple "markup language." (A "markup language"
is a set of instructions that tell a computer what to do with
chunks of information.) Many of these folks belong to an organization
called the "World Wide Web Consortium," which is known as the "W3C" for short.
Created in 1994, the W3C's mission is to lead the World Wide Web to its full potential.
(Find out more about the W3C at www.w3c.org.)
The world already had several markup languages, the most famous
of which was Standard Generalized Markup Language (SGML).
SGML is very powerful, and it's good for a lot of things - but it
is very complicated.
The W3C folks decided to create a simpler version of SGML, which
they did. They called it XML.
|
One big reason that the world needs XML is that HTML, the markup language used on the
Web, is causing problems for programmers. HTML is pretty good at
displaying text and graphics in different fonts and colors, etc.,
but HTML isn't good at describing the structure of a collection
of information (the meanings of different pieces of
information and the relationships among the different pieces of information).
XML, on the other hand, is very good at describing the structure of
a collection of information. You can also use XML technology to
display information in different fonts and colors, etc. We'll talk
about that a little later.
|
There are many uses for XML, but mainly it is being used for three things:
- to store and organize information that needs to be displayed in a Web browser
- to store and organize information that needs to be printed on paper
- to exchange information between computers.
|
Over the next few years, XML will gradually replace HTML as a format for Web documents.
Why? Because XML makes it easier to create programs
that provide information over the Web (easier than using HTML). That's because - as we've
already pointed out - XML is has a rigid structure, which simplifies things for
programmers.
The following scenario illustrates this point.
Scenario: Displaying information about faculty members
You can use HTML to display the faculty_members information
on a Web site. You could lay out the information like this:
| Name |
Date of Birth |
Gender |
Job Title |
Salary |
|
Joanne
Gayle
Jones
|
08/28/1955
|
female
|
teacher
|
42,000
|
|
Ruth
Ann
Green
|
08/25/1978
|
female
|
teacher's assistant
|
21,500
|
|
Vincent
John
Pellio
|
07/16/1959
|
male
|
teacher
|
36,500
|
Because this information is arranged in columns and rows,
and because each column is labeled at the top,
a person looking at this information on a computer screen
can understand easily what the information means.
However, when you look at the HTML code that is responsible
for creating the
columns and rows of information, it's not at all easy to
understand what the information means. Here is a portion of
the HTML code that creates the columns and rows of information::
<TR>
<TD>Joanne Gayle Jones</TD>
<TD>08/28/1955</TD>
<TD>female</TD>
<TD>teacher</TD>
<TD>42,000</TD>
</TR>
<TR>
<TD>Ruth Ann Green</TD>
<TD>08/25/1978</TD>
<TD>female</TD>
<TD>teacher's assistant</TD>
<TD>21,500</TD>
</TR>
Right away you can see that HTML code doesn't convey as
much structural information as XML code. For example, this HTML
code certainly doesn't make it clear that 08/28/1955 is
somebody's birthday, nor does it explain that the numeric
values are salaries.
The problem is that the tags used in HTML are not semantically meaningful -
that is, the tags are concerned with how the information looks as
opposed to being concerned with what the information means.
(In our example here, the information inside each
set of <TR> and </TR> tags appears on one row in a table, and the
information inside each set of <TD> and </TD> tags appears in
one individual "slot" or "cell" in a row.)
So the bottom line is that HTML doesn't have a predictable structure with
a descriptive tag for each bit of information. This causes problems on
the Internet because of the way that Web programming works. Without
getting into details, suffice it to say that:
- Web sites work more slowly with HTML than with XML.
- Lots of huge files are being sent around the Internet all the time; these
files would be smaller — and they would need to be sent around the
Internet less frequently — if XML were being used for Web pages instead
of HTML.
Just as you can use XML to store and organize information that will
be displayed on the Web,
you can also use it to store and organize information that will be
printed on paper.
In fact, you can use XML to
create documents that will be printed on paper, displayed on the Web, or
both. When we say "printed on paper," we're not just talking about printing a
document that's displayed in your Web browser by clicking on
File and then clicking on Print. Instead, we are
talking about
using the same set of XML files as a basis for printing
information on paper in a format (layout) that might be entirely
different than the format that is used to display
that same information on the Web. We are also talking about the
concept of using the same set of XML files as a basis for
printing several different paper documents, each of which has a
different layout but contains essentially the same information.
Over the last few years, programmers have come to realize that using XML
is a really good way for computers to exchange information.
Now, XML is well on its way to becoming the standard for exchanging all
kinds of information on the Internet and for buying and selling things
on the Internet ("e-business" and "e-commerce").
There are several ways to use XML for exchanging information between
computers. One way is the following:
- Programmers get together and decide exactly what kind of
information needs to be exchanged.
- These programmers create an XML-based language that is appropriate for
their situation, and they write a Document Type Definition (DTD) or
an XML Schema that describes this language.
- The programmers write or obtain programs that can understand
XML and can also understand the DTD or the XML Schema (whichever
is being used).
- When one computer needs to give information to another
computer, the computer that is giving the information writes a
message to the computer that will receive the information. The
language used in the message is the XML-based language specified by
the DTD or XML Schema.
- When the other computer receives the message, it can understand
the message because it has available the DTD or the XML Schema
for the language used in the message.
* * * TIME TO REVIEW * * *
Let's do another review. Here we go:
- XML is a set of rules that specify how to create a language.
- We refer to languages that follow XML's rules as "XML-based languages."
- A particular XML-based language is described by a DTD or by an XML Schema.
- Humans and computers depend on a DTD or an XML Schema to understand a particular XML-based language.
- XML is good at describing how a collection of information is structured. You can also
use XML technology to control how the information is displayed. (We talk about this in the
next section.)
- HTML is good at describing how to display information, but HTML usually doesn't tell you very much about the structure of the information.
- You can use XML technology to store and organize information that will be
displayed on the Web and/or printed
on paper and/or exchanged between different computers.
- Over the next few years, Web programmers will use XML more and more and will use HTML less and less.
|
The thing that programmers really like about XML technology is that structure
and presentation are separated. Separating structure from presentation is great from a programmer's
perspective, because it makes it easy to present the data in many
different formats.
|
Programmers use a variety of technologies to present XML information.
One of the most interesting and powerful
XML-presentation technologies is Extensible Stylesheet Language (XSL).
|
XSL is a language that programmers can use to
describe how XML information should be rendered (presented). It was created by
the same group of people who created XML. It works like this:
- A programmer creates an XSL file that contains instructions
for generating code that will present the information in the desired format.
- The code in the XML file and the code in the XSL file is parsed by an
XML Parser and stored in computer memory.
- The parsed XML code and the parsed XSL code are processed together by a program
called an XSL Processor, which produces a file that is
used to render the XML information. In the most common scenario, the XSL code
contains instructions that tell the XSL Processor to create HTML code. However, it is possible for
programmers to
write XSL code that tells the XSL Processor to create other types
of code. We will talk a little more about this later.
This process of using an XSL Processor to "merge" XSL code with
XML code is called "Extensible Stylesheet Language Transformation,"
or "XSLT" for short.
To illustrate how XSLT works, we'll use the XML code
that we showed earlier for the
"faculty_members" data. Below is an XSL
file that will present the "faculty_members" data in
columns and rows.
(XSL is not as easy to understand as XML. Don't be concerned about trying to
understand everything about this XSL code. We are showing this XSL code
here just to give you an idea of what it looks like.)
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<xsl:apply-templates select="faculty_members"/>
</xsl:template>
<xsl:template match="faculty_members">
<HTML>
<HEAD>
<TITLE>faculty_members data displayed in table format</TITLE>
<BASEFONT FACE="Arial, Helvetica, sans-serif"/>
</HEAD>
<BODY>
<TABLE>
<TR>
<TH ALIGN="LEFT">Name</TH>
<TH ALIGN="LEFT">Date of Birth</TH>
<TH ALIGN="LEFT">Gender</TH>
<TH ALIGN="LEFT">Job Title</TH>
<TH ALIGN="LEFT">Salary</TH>
</TR>
<xsl:for-each select="faculty_member">
<TR>
<TD>
<xsl:value-of select="name/first"/>
<xsl:value-of select="name/middle"/>
<xsl:value-of select="name/last"/>
</TD>
<TD>
<xsl:value-of select="date_of_birth"/>
</TD>
<TD>
<xsl:value-of select="gender"/>
</TD>
<TD>
<xsl:value-of select="job_title"/>
</TD>
<TD>
<xsl:value-of select="salary"/>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
When you use an XML Parser and an XSL Processor to merge the "faculty_members"
XML code together with the above XSL code, you get HTML code that displays
a table like the one we showed earlier.
* * * TIME TO REVIEW * * *
- XML technology allows programmers to
separate the task of structuring information from the
task of presenting information.
- Separating structure from presentation can make it easier to write programs.
- Extensible Stylesheet Language (XSL) is a language that
programmers can use to describe how XML information should be presented.
- To use XSL to present XML information, you need two types of computer programs:
an XML Parser and an XSL Processor. The XML Parser analyzes XML code and XSL
code and puts it into computer memory, and an XSL Processor uses XML code together
with XSL code to create some other type of code.
- In the typical scenario, the type of code that an XSL Processor
creates is HTML code; and
the HTML code is use to present the XML information in a browser.
|
As we've said, you need an XSL Processor if you want to use an XSL
file to format the information in an XML file.
If you have a fairly new version of the Microsoft Internet Explorer
browser, you already have an XSL Processor - because there's an XSL Processor
built into recent versions of Microsoft Internet Explorer. Certain
other browsers might also have XSL Processors.
(NOTE: If your browser has an XSL Processor, you can assume that it also has an
XML Parser. As we explained earlier, both are needed if you want to use XSL
to present XML information. We won't mention the XML Parser in our discussions
below, but keep in mind that - as we said before - the XML Parser loads the XML code
and the XSL code into memory, and then the XSL Processor takes over and "merges"
the XML code and the XSL code.)
|
If your browser has an XSL Processor, when you click on the
"http://www.CitationSoftware.com/faculty_members_table.xml"
link below, your browser will display the
"faculty_members" information in columns and rows, like this:
| Name |
Date of Birth |
Gender |
Job Title |
Salary |
|
Joanne
Gayle
Jones
|
08/28/1955
|
female
|
teacher
|
42,000
|
|
Ruth
Ann
Green
|
08/25/1978
|
female
|
teacher's assistant
|
21,500
|
|
Vincent
John
Pellio
|
07/16/1959
|
male
|
teacher
|
36,500
|
Try it now - and after you've clicked on the link, click the "Back"
button in your browser to return to this text and continue reading.
www.CitationSoftware.com/faculty_members_table.xml
If your browser doesn't have an XSL Processor, you'll get an error
message.
For the sake of our discussion, let's assume that your browser does have an XSL
Processor and that the browser displayed the columns and
rows of information. (If this didn't
happen for you, you can still follow along with this discussion.
Later, we'll tell you how to get an XSL Processor.)
WHAT HAPPENED?
To understand how it all works, let's take a look at the
"faculty_members_table.xml" file, which is the file that
is referenced by the link that you clicked on.
Here is what the "faculty_members_table.xml" file looks like:
<?xml version='1.0' ?>
<?xml-stylesheet type="text/xsl" href="faculty_members_table.xsl"?>
<faculty_members>
<faculty_member>
<name>
<first>Joanne</first>
<middle>Gayle</middle>
<last>Jones</last>
</name>
<date_of_birth>08/28/1955</date_of_birth>
<gender>female</gender>
<job_title>teacher</job_title>
<salary>42,000</salary>
</faculty_member>
<faculty_member>
<name>
<first>Ruth</first>
<middle>Ann</middle>
<last>Green</last>
</name>
<date_of_birth>08/25/1978</date_of_birth>
<gender>female</gender>
<job_title>teacher's assistant</job_title>
<salary>21,500</salary>
</faculty_member>
<faculty_member>
<name>
<first>Vincent</first>
<middle>John</middle>
<last>Pellio</last>
</name>
<date_of_birth>07/16/1959</date_of_birth>
<gender>male</gender>
<job_title>teacher</job_title>
<salary>36,500</salary>
</faculty_member>
</faculty_members>
The first thing to notice is that the XML "faculty_members"
code (everything between
<faculty_members> and </faculty_members>)
is exactly the same XML code that you saw earlier in this discussion.
Now look at the second line of code - the line that says
<?xml-stylesheet type="text/xsl" href="faculty_members_table.xsl"?>
This code tells your browser's XSL Processor to find the file named
"faculty_members_table.xsl" and process it together with the
"faculty_members" XML code that's in the
"faculty_members_table.xml" file.
The "faculty_members_table.xsl," file contains XSL
code which — when processed by the XSL Processor — creates
HTML code that lays out the "faculty_members" information
in table format (i.e., columns and rows). The
"faculty_members_table.xsl" file looks like this (it's
the same XSL code that we
showed you a little earlier):
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<xsl:apply-templates select="faculty_members"/>
</xsl:template>
<xsl:template match="faculty_members">
<HTML>
<HEAD>
<TITLE>faculty_members data displayed in table format</TITLE>
<BASEFONT FACE="Arial, Helvetica, sans-serif"/>
</HEAD>
<BODY>
<TABLE>
<TR>
<TH ALIGN="LEFT">Name</TH>
<TH ALIGN="LEFT">Date of Birth</TH>
<TH ALIGN="LEFT">Gender</TH>
<TH ALIGN="LEFT">Job Title</TH>
<TH ALIGN="LEFT">Salary</TH>
</TR>
<xsl:for-each select="faculty_member">
<TR>
<TD>
<xsl:value-of select="name/first"/>
<xsl:value-of select="name/middle"/>
<xsl:value-of select="name/last"/>
</TD>
<TD>
<xsl:value-of select="date_of_birth"/>
</TD>
<TD>
<xsl:value-of select="gender"/>
</TD>
<TD>
<xsl:value-of select="job_title"/>
</TD>
<TD>
<xsl:value-of select="salary"/>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
As we've said, when the browser's XSL Processor processes the XSL code
in the "faculty_members_table.xsl" file along with the
XML code in the "faculty_members_table.xml" file, what
the XSL Processor creates is HTML code that displays the information
in columns and rows in your browser.
That HTML code looks like this:
<HTML>
<HEAD>
<TITLE>faculty_members data displayed in table format</TITLE>
<BASEFONT FACE="Arial, Helvetica, sans-serif"/>
</HEAD>
<BODY>
<TABLE>
<TR>
<TH ALIGN="LEFT">Name</TH>
<TH ALIGN="LEFT">Date of Birth</TH>
<TH ALIGN="LEFT">Gender</TH>
<TH ALIGN="LEFT">Job Title</TH>
<TH ALIGN="LEFT">Salary</TH>
</TR>
<TR>
<TD>Joanne Gayle Jones</TD>
<TD>08/28/1955</TD>
<TD>female</TD>
<TD>teacher</TD>
<TD>42,000</TD>
</TR>
<TR>
<TD>Ruth Ann Green</TD>
<TD>08/25/1978</TD>
<TD>female</TD>
<TD>teacher's assistant</TD>
<TD>21,500</TD>
</TR>
<TR>
<TD>Vincent John Pellio</TD>
<TD>07/16/1959</TD>
<TD>male</TD>
<TD>teacher</TD>
<TD>36,500</TD>
</TR>
</TABLE>
</BODY>
</HTML>
If you're one of the lucky folks that has a browser with a built-in
XSL Processor, click now on the following link:
www.CitationSoftware.com/faculty_members_sentences.xml.
Your browser will display the following:
Joanne Gayle Jones is a female teacher who was born on 08/28/1955 and earns $42,000 per year.
Ruth Ann Green is a female teacher's assistant who was born on 08/25/1978 and earns $21,500 per year.
Vincent John Pellio is a male teacher who was born on 07/16/1959 and earns $36,500 per year.
(If your browser doesn't have a built-in XSL Processor, just follow along with our discussion.)
The link that you clicked on references the "faculty_members_sentences.xml" file.
This is what that file looks like:
<?xml version='1.0' ?>
<?xml-stylesheet type="text/xsl" href="faculty_members_sentences.xsl"?>
<faculty_members>
<faculty_member>
<name>
<first>Joanne</first>
<middle>Gayle</middle>
<last>Jones</last>
</name>
<date_of_birth>08/28/1955</date_of_birth>
<gender>female</gender>
<job_title>teacher</job_title>
<salary>42,000</salary>
</faculty_member>
<faculty_member>
<name>
<first>Ruth</first>
<middle>Ann</middle>
<last>Green</last>
</name>
<date_of_birth>08/25/1978</date_of_birth>
<gender>female</gender>
<job_title>teacher's assistant</job_title>
<salary>21,500</salary>
</faculty_member>
<faculty_member>
<name>
<first>Vincent</first>
<middle>John</middle>
<last>Pellio</last>
</name>
<date_of_birth>07/16/1959</date_of_birth>
<gender>male</gender>
<job_title>teacher</job_title>
<salary>36,500</salary>
</faculty_member>
</faculty_members>
The only difference between this file and the
"faculty_members_table.xml" file is
that - in this file - the "xsl:stylesheet" command
contains the filename "faculty_members_sentences.xsl"
instead of the filename "faculty_members_table.xsl." The XSL
Processor therefore uses the code in the
"faculty_members_sentences.xsl" file to format
the information. The code in the "faculty_members_sentences.xsl"
file causes the XSL Processor to generate HTML code that presents the
information in sentence format rather than table format - that's why
your browser displays the information in sentences instead of columns and rows.
In case you're interested, this is what the "faculty_members_sentences.xsl"
file looks like:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<xsl:apply-templates select="faculty_members"/>
</xsl:template>
<xsl:template match="faculty_members">
<HTML>
<HEAD>
<TITLE>faculty_members data displayed in sentence format</TITLE>
<BASEFONT FACE="Arial, Helvetica, sans-serif"/>
</HEAD>
<BODY>
<xsl:for-each select="faculty_member">
<xsl:value-of select="name/first"/>
<xsl:value-of select="name/middle"/>
<xsl:value-of select="name/last"/>
is a
<xsl:value-of select="gender"/>
<xsl:value-of select="job_title"/>
who was born on
<xsl:value-of select="date_of_birth"/>
and earns
$<xsl:value-of select="salary"/>
per year.<BR/><BR/>
</xsl:for-each>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
The HTML code generated by the XSL Processor looks like this:
<HTML>
<HEAD>
<TITLE>faculty_members data displayed in sentence format</TITLE>
<BASEFONT FACE="Arial, Helvetica, sans-serif" />
</HEAD>
<BODY>
Joanne Gayle Jones is a female teacher
who was born on
08/28/1955
and earns
$42,000
per year.<BR />
<BR />
Ruth Ann Green is a female teacher's
assistant who was born on
08/25/1978
and earns
$21,500
per year.<BR />
<BR />
Vincent John Pellio is a male teacher
who was born on
07/16/1959
and earns
$36,500
per year.<BR />
<BR />
</BODY>
</HTML>
|
The main thing to understand is this:
|
When you clicked on the link for "faculty_members_table.xml,"
the layout of the information in the resulting browser window was very
different than the layout that you got when you
clicked on the link for "faculty_members_sentences.xml."
However, the two XML files are exactly the same except for the
name of the XSL file that is given in the "<xsl:stylesheet>"
command. The two XSL files ("faculty_members_table.xsl" and
"faculty_members_sentences.xsl") are responsible for
the two different layouts.
Suppose we want to display the "faculty_members" information so that
visually impaired people can read it easily. We can use XSL to do that, too.
If your browser has an XML Processor, click on the following link:
www.CitationSoftware.com/faculty_members_large_print_sentences.xml.
Your browser should display the "faculty_members" information in very large
type, in sentence format.
The large-print presentation was accomplished as follows:
- An XSL file named "faculty_members_large_print_sentences.xsl" was
created. The commands in this file tell the XSL Processor to generate HTML code that displays
large-print sentences containing the "faculty_members" information.
- An XML file named
"faculty_members_large_print_sentences.xml" was
created. This file is exactly the same as the other two XML files that we've talked about -
except for the fact that the "xsl:stylesheet" command contains the filename
"faculty_members_large_print_sentences.xsl."
File "faculty_members_large_print_sentences.xsl" looks like this:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<xsl:apply-templates select="faculty_members"/>
</xsl:template>
<xsl:template match="faculty_members">
<HTML>
<HEAD>
<TITLE>faculty_members data displayed in sentence format</TITLE>
</HEAD>
<BODY>
<FONT SIZE="6">
<xsl:for-each select="faculty_member">
<xsl:value-of select="name/first"/>
<xsl:value-of select="name/middle"/>
<xsl:value-of select="name/last"/>
is a
<xsl:value-of select="gender"/>
<xsl:value-of select="job_title"/>
who was born on
<xsl:value-of select="date_of_birth"/>
and earns
$<xsl:value-of select="salary"/>
per year.<BR/><BR/>
</xsl:for-each>
</FONT>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
And file "faculty_members_large_print_sentences.xml" looks like this:
<?xml version='1.0' ?>
<?xml-stylesheet type="text/xsl"
href="faculty_members_large_print_sentences.xsl"?>
<faculty_members>
<faculty_member>
<name>
<first>Joanne</first>
<middle>Gayle</middle>
<last>Jones</last>
</name>
<date_of_birth>08/28/1955</date_of_birth>
<gender>female</gender>
<job_title>teacher</job_title>
<salary>42,000</salary>
</faculty_member>
<faculty_member>
<name>
<first>Ruth</first>
<middle>Ann</middle>
<last>Green</last>
</name>
<date_of_birth>08/25/1978</date_of_birth>
<gender>female</gender>
<job_title>teacher's assistant</job_title>
<salary>21,500</salary>
</faculty_member>
<faculty_member>
<name>
<first>Vincent</first>
<middle>John</middle>
<last>Pellio</last>
</name>
<date_of_birth>07/16/1959</date_of_birth>
<gender>male</gender>
<job_title>teacher</job_title>
<salary>36,500</salary>
</faculty_member>
</faculty_members>
The HTML code generated by the XSL Processor looks like this:
<HTML>
<HEAD>
<TITLE>faculty_members data, large print, sentence format</TITLE>
</HEAD>
<BODY>
<FONT SIZE="6">
Joanne Gayle Jones is a female teacher
who was born on
08/28/1955
and earns
$42,000
per year.<BR />
<BR />
Ruth Ann Green is a female teacher's assistant
who was born on
08/25/1978
and earns
$21,500
per year.<BR />
<BR />
Vincent John Pellio is a male teacher
who was born on
07/16/1959
and earns
$36,500
per year.<BR />
<BR />
</FONT>
</BODY>
</HTML>
|
|
* * * TIME TO REVIEW * * *
It's time for another review.
- An XSL Processor uses XML code and XSL code to
produce some other kind of code - typically HTML code.
- If you have an XSL Processor, you can use several different XSL files to
present the same XML information in several different ways.
- Some Internet browsers have a built-in XSL Processor.
|
That, my friend, is a very important question!
The answer to the question depends on your situation.
- If you are developing a Web site for an environment where
all your site visitors will be using browsers that
have built-in XSL Processors, then your job will be relatively easy.
Your Web server can send XML code directly to your visitors'
browsers, along with "<xsl:stylesheet>" commands
that reference XSL files. Each visitor's
browser will use its built-in XSL Processor to process the XML
code and the XSL code, producing HTML code.
This is the technique that we used
above for the "faculty_members" examples.
This setup will work if, for example, you are developing a
site to be used only by employees of a corporation where
everybody uses a current version of the Microsoft Internet
Explorer browser.
- If you are developing a Web site that can be used by
anybody in the world, then your job will be more challenging;
because some of your visitors will have a browser without
a built-in XSL Processor. You can't send XML
code to your visitors' browsers.
There are a few ways
to handle this situation, one of which is the following: use
an XSL Processor on the Web server to generate HTML code from
XML code and XSL code; then send the HTML code to your
visitors' browsers. For this type of system, you can use
the XSL Processor in "XMLwriter" or "Cocoon,"
both of which are described below.
This setup will work if, for example, you are developing a
Web site for marketing and selling products or services on the Internet.
|
We've already alluded to the fact that not all XSL Processors are
built into browsers. Some XSL Processors are built into other types of applications
(applications that are not browsers), and some XSL
Processors are stand-alone programs.
There quite a few XSL Processors available. Here is some
information about a couple of them:
- XMLwriter. This is an XML editor with an XSL Processor
built into it. You can use XMLwriter's XSL Processor interactively,
from XMLwriter's graphical user interface; you can also
use the XSL Processor non-interactively, from the command line.
XMLwriter runs under Windows 95/98/NT/2000. It is easy to install
and easy to use. XMLwriter is a very nice tool for learning about
XML technology and for doing serious work with XML technology.
When you use XMLwriter for editing, it displays color coding
that helps you to catch typing
errors when you are typing XML code, XSL code, DTD code, and some
other kinds of code ̬ including HTML.
In addition to what we've described here, XMLwriter performs many
other useful tasks. And XMLwriter has an excellent on-line
XML reference guide.
XMLwriter is available from Wattle Software at
http://xmlwriter.net. It
costs $42.00. You can download a 30-day-trial version for free.
- Cocoon. This a Java publishing "framework" that
programmers can use to develop XML-based Web sites. Cocoon can do
many things, one of which is to function as an XSL Processor.
Cocoon is more difficult to install than XMLwriter.
Cocoon runs on many different kinds of computers. You can download
it for free from http://cocoon.apache.org/2.0//,
and you can use it for free as long as you abide by the terms of the
license agreement.
If you are using a Windows 95/98/NT/2000 computer and
you want to start learning about XML quickly, we
recommend that you
download and install XMLwriter.
|
In our discussion, we've focused on
displaying XML information in a Web browser by using an XSL Processor
to generate HTML code.
We've also touched upon the notion of using XML to store and organize
information that will be printed on paper.
In addition, we've discussed the fact
that computer programs can use XML to exchange information.
But there is much more to XML! One of the really exciting aspects
of XML technology is that it provides a good technical foundation for
presenting information in MANY different ways.
Here are some examples:
- You can present XML information in Braille format.
- You can use "text-to-speech" technology that presents XML information
to Web site visitors by talking to them.
- You can convert XML information to various document formats, such as PDF
(Adobe's Portable Document Format), RTF (Microsoft's Rich Text Format),
and others.
- You can format XML information for presentation on
cellular phones and on Personal Digital assistants (PDAs) like the Palm
devices.
The key to all of these things is the fact that - as
we've said several times already - XML technology allows you to
keep the structure of a collection of information separated from
the presentation of that information.
|
Go to the following Web addresses to learn more about XML and to find
software for working with XML:
www.xml.com - This
Web site features a mix of information and services
for the XML community.
www.objectinnovations.com - This
is the corporate Web site for Object Innovations, a company
that offers excellent training materials for XML-related technologies.
www.xml.org - Go
to this Web site to use the XML.ORG Registry, which
lets you access the fast-growing body of XML specifications, schemas and vocabularies that
are being developed.
www.w3c.org - This
is the Web site for the World Wide Web Consortium (W3C), which develops interoperable
technologies (specifications, guidelines, software, and tools)
to lead the Web to its full potential.
www.ibiblio.org/xml/books/bible2/chapters/ch18.html - This
link takes you to Chapter 18 of the XML Bible by Elliotte Rusty Harold. This chapter of
the XML Bible talks in detail about XSL Formatting Objects (XSL-FO) and explains how
to use the XSL-FO technology.
http://webreference.com/xml/ - This
area of the webreference.com site contains lots of information about XML and about XML-related
technologies. Most of this information is written in a down-to-earth style that can be
understood easily.
http://cocoon.apache.org/2.0/ - This
is the Web site for the Cocoon Project. You can get the Cocoon XSL Processor here.
http://xmlwriter.net - This
is the Web site for Wattle Software. You can get the XMLwriter software here.
www.arbortext.com - This
is the Web site for Arbortext, a leading provider of XML-based information applications.
www.w3.org/TR/WAI-WEBCONTENT-TECHS/#structure - This
is a link to a document entitled "Techniques for Web Content Accessibility Guidelines 1.0."
It talks about how to make Web sites accessible to the disabled community.
|
|
|

Let our Wizard help you find the right product!
|
|
Copyright © 2010 Citation Software Inc.
info@CitationSoftware.com
888-260-7316
www.CitationSoftware.com
|
|