Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News

SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
Got XSLT?
Got XSLT?

Extensible Stylesheet Language Transformation (XSLT) is part of the XSL standard. The most popular use of XML and XSL is to create a separation of content and presentation. Although several XML/XSLT articles and tutorials are available, none really explain and demonstrate the true flexibility and ease of transforming a single XML document into data formats such as HTML, WML, and VoiceXML.

XSLT provides an easy, efficient transformation for simple applications. In this article we'll focus on marking up a book catalog using XML and Microsoft's Internet Explorer 5.0 browser to perform the transformation. I prefer to use XML in our example because we can create other sets of HTML, WML, or even VoiceXML pages from the same XML document. I'll start with HTML; subsequent articles will deal with the other formats. I'm assuming readers are familiar with HTML, XML, and XSLT (see the Resources section for more background information).

In this tutorial I'll focus on creating XML and XSL documents and the use of an IE 5.0 XML parser and XSL engine. IE 5.0 is currently the only widely available browser that contains an XML parser with an XSL engine. The example code in this tutorial will work only in IE 5.0 or later.

XML and XSL are increasingly used to enable customized data presentation for different browsers, devices, and users. By using XML documents along with XSL stylesheets on the client, middletier, or server, we can transform, organize, and present XML data tailored to individual users for a variety of client devices, including graphical and nongraphical Web browsers, PDAs such as Palm Pilots, digital cell phones, and pagers. In doing so, we can focus on business applications, without concern for the kind of output devices that will present the data now or in the future.

XSL actually consists of three languages:

  • Extensible Stylesheet Language Transformation (XSLT): A language to transform XML
  • XPath: A language to define XML parts or patterns
  • XML Stylesheet Language Format Object (XSL-FO): A language to define XML display
XSLT, the most important part of the XSL standard, transforms XML documents into other types of documents or into other XML documents. A common way to describe the process is to say that XSL uses XSLT to transform an XML document to another document type. A stylesheet contains instructions that tell a processor (such as a Web browser, print composition engine, or document reader) how to translate the logical structure of a source document into a presentation structure. Stylesheets typically contain instructions to color the content of certain elements blue or to number figures sequentially throughout the document. An XML document can refer to an XSL document to describe how it should be presented.

XSLT can be used on either the back end or within the browser. IE 5.0 has an XSLT processor built in, but it isn't 100% compatible with the latest release of the W3C XSL standard. (See sidebar or Resources section for more information.)

Creating the XML Document
Why convert XML into HTML when you can write HTML code in the first place? The obvious answer is because by using XML we can create another set of HTML, WML, or even VoiceXML pages from the same document. This should provide ample motivation for all of us!

Let's create an XML document representing a catalog of books. Start with your data in its current form. As an example, my data format is a yellow sticky note plastered on my library wall, as follows:

Enterprise JAVABEANS
$34.95
Professional XML
$49.99
Java and XML
$39.95

Since XML is a text-based markup language, we can use any text editor to create the XML document. XML authoring editors can help create XML elements and tags, such as the freely available Microsoft XML Notepad (see Resources). Listing 1 illustrates book information in XML syntax - mybooks.xml.

The XML document contains the following additional information: ISBN, CATEGORY, and RELEASE_DATE.

You're free to add or delete data to meet your catalog preference. We won't use a DTD to validate our ".xml" file since we're not interested in validation in this article.

If you load the XML document as written in Listing 1, using IE 5.0, you'll see the display shown in Figure 1. This is a raw form of XML document. In fact, IE 5.0 had applied a default stylesheet to an XML document without any stylesheet specified.

The Goal
The goal is to produce a Web page that looks like Figure 2.

Creating the Stylesheet Document
Now that we have the book information marked up in XML, let's see how we can devise a stylesheet for displaying the mybooks.xml document nicely on the IE 5.0 browser.

XSLT is basically a declarative high-level language. It has several programming-like features such as if, choose-when-otherwise, sort, filter, for-each, and many others. Listing 2 shows a complete XSL file to render our XML file into HTML file.

In Listing 1 if we uncomment a reference of our XSL stylesheet (line number 3) by simply removing "<!---"\" and "-->" around the statement so it appears as:

<?xml-stylesheet type="text/xsl" href=
"books_html.xsl"?>

and then load the XML document using IE 5.0 browser, we'll see the HTML page as displayed in Figure 2.

Understanding Our Stylesheet
Let's take a closer look at the books_html.xsl stylesheet. The first line of the XSLT is:

<?xml version="1.0"?> This indicates XSLT is an XML document, and will comply with the XML syntax.

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/TR/WD-xsl">

Next, we define the namespace for the XSL stylesheet with the <xsl:stylesheet> element.

<xsl:template match="/">

The template has been wrapped with match="/" to indicate that it corresponds to the root (/) of the XML source document.

<xsl:for-each select="BOOKS/BOOK">

The XSL <xsl:for-each> element locates elements in the XML document and repeats a part of the template for each one.

<xsl:value-of select="CATEGORY"/>

The XSL <xsl:value-of> element can be used to select the value of the element matched by the select predicate.

The XSL stylesheet then closes all open XML tags in order, with no nesting allowed.

Conclusion
This article shows the ease of using an IE 5.0 embedded XSLT engine to convert and render XML into HTML. Since it would be wiser and more interesting if our book catalog were accessible not only from standard Web browsers, but also via Wireless Access Protocol (WAP) devices and even VoiceXML, in my next two articles I'll do just that.

Enterprise JAVABEANS
$34.95
Professional XML
$49.99
Java and XML
$39.95

Resources

Additional Information
XSLT in IE 5.0 isn't 100% compatible with the latest release of the W3C XSL standard. IE 5.0 was released when the XSL standard was still a W3C Working Draft. MSXML 2.0 is the XML parser that shipped with IE 5.0; MSXML 2.5 shipped with Windows 2000. According to Microsoft, MSXML 3.0 is 100% compatible with the official W3C XSL Recommendation. In April 2001 Microsoft released XML Parser (MSXSL) 4.0 technology preview release - a preliminary release of MSXML 4.0. Microsoft claims it offers improved performance, fixes for known problems, and more complete documentation. However, most prominent among the additions to the technology preview is the support of the latest W3C XML Schema proposed recommendation, dated March 30, 2001.

The main reason I'm working with MSXML 2.0 in this tutorial is because IE 5.0 with MSXML 2.0 is still widely in use on the Internet. Some developers aren't even aware of the incompatibility issue, and waste valuable time and effort getting the transformation to work. Additionally, having to download MSXML 3.0 or a newer version of MSXML isn't necessary for our simple example. In fact, the only visible difference you'll find is the XSL stylesheet declaration.

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) IE 5.0 with MSXML 2.0 (from the XSL Working Draft):

<xsl:stylesheet xmlns:xsl="http://
www.w3.org/TR/WD-xsl">

About Shouki Souri
Shouki Souri is a lead Software Engineer at PanAmSat Corporation. He has several years of experience working with Java, CORBA, XML/XSL, C/C++ and other technologies. He holds a bachelor’s degree in Electrical Engineering and a master’s degree in Computer Science..

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Latest Cloud Developer Stories
Swisscom, the Swiss telecom, is going into the cloud business. Its subsidiary Swisscom IT Services AG has signed up with Red Hat as a Certified Cloud Provider and launched a public cloud Infrastructure-as-a-Service (IaaS) cloud targeting enterprise-class customers primarily in ...
Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP)....
In a surprise move on Tuesday, January 10, Oracle wheeled out its Big Data Appliance. That’s the one it said in October would be ready sometime in the first half. Only nobody believed it meant early in the first half. Heck, it’s not even clear anybody thought Oracle could make ...
Rackspace Hosting, the service leader in cloud computing, on Thursday announced its acquisition of SharePoint911, an industry leader in SharePoint consulting, training, and "JumpStart" services within SharePoint. The unification of both companies provides capabilities to deliver ...
CloudLinux, Inc., on Thursday released CafeFS 3, a virtualized file system for shared hosters that cages each customer within its own virtualized file system. CageFS becomes part of CloudLinux OS at no additional charge. CloudLinux OS, the only commercially-supported Linux OS m...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE

Breaking Cloud Computing News

BEACHWOOD, Ohio, Feb. 16, 2012 /PRNewswire/ -- DDR Corp. (NYSE: DDR) today announced operating re...