Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Display XML with Cascading Stylesheets, Part 2: Use Cascading Stylesheets to display XML

Advanced techniques to present XML in Web browsers

Uche Ogbuji (uche.ogbuji@fourthought.com), Principal consultant, Fourthought Inc.
Uche Ogbuji is a consultant and co-founder of Fourthought Inc., a software vendor and consultancy specializing in XML solutions for enterprise knowledge management. Fourthought develops 4Suite, an open source platform for XML, RDF, and knowledge-management applications. Mr. Ogbuji is also a lead developer of the Versa RDF query language. He is a computer engineer and writer born in Nigeria, living and working in Boulder, Colorado, USA. You can contact Mr. Ogbuji at uche.ogbuji@fourthought.com.

Summary:  In a previous tutorial, Uche Ogbuji showed how to use Cascading Stylesheets (CSS) to display XML in browsers, presenting basic techniques. However, as you get familiar with CSS, you'll find numerous tricks, traps, and nuances. This tutorial builds on the basics in the earlier one to cover intermediate and advanced topics like differences in compliance and rendering details across browsers, handling of different media such as aural (speech) and print, and interaction with other browser and XML technologies such as XSLT and JavaScript.

View more content in this series

Date:  25 Feb 2005
Level:  Introductory PDF:  A4 and Letter (229 KB)Get Adobe® Reader®

Activity:  7877 views
Comments:  

Introduction

The many nuances of CSS

In a previous tutorial, Uche Ogbuji showed how to use Cascading Stylesheets (CSS) to display XML in browsers, presenting basic techniques. However, as anyone who has tried to master CSS in the world of HTML and JavaScript can attest, you'll find numerous tricks, traps, and nuances. The same is true when using CSS with XML. You have to watch out for:

  • Differences in compliance and rendering details across browsers
  • Handling of different media such as aural (speech) and print
  • Interaction with other browser and XML technologies such as XSLT and JavaScript

You may also be interested in matters such as:

  • The use of CSS embedded in important XML vocabularies such as SVG
  • Linking, forms, and other user interface features relating to browser styling

This tutorial builds on the basics in the earlier one to cover these intermediate and advanced topics.


Who should take this tutorial?

A lot of XML eventually finds it way to Web browsers in one way or another, and CSS is a great way to make XML presentable in browsers. CSS is best known as the recommended method for specifying the presentation of HTML, but recent versions also support XML, and have been embraced by browser vendors as the best-supported means of displaying XML. CSS is also used in other XML vocabularies such as SVG and XForms.

Anyone who works with XML should take this tutorial. Even if CSS doesn't cover your needs for production Web publishing, it is a great tool for debugging and experimentation. It also has rich interaction with other XML technologies, and you are likely to run into CSS in many unexpected cases.


Prerequisites

This tutorial assumes knowledge of XML, and some basic knowledge of CSS. If you aren't familiar with XML, I recommend that you first take the "Introduction to XML" tutorial here on developerWorks.

You should also be familiar with the use of CSS to style XML in browsers. To learn this, take the previous tutorial, "Use Cascading Stylesheets to display XML".

I recommend, but do not require, familiarity with XML Namespaces and XSLT. If you aren't familiar with XSLT, you might want to take the tutorial "Create multi-purpose Web content with XSLT tutorial."

I highly recommend that you try out the examples in this tutorial. To do so you need a Web browser that supports XML and CSS Level 2 or better. Where applicable, I present the output of examples using Firefox 1.0 on Fedora Core Linux. Firefox is a popular Web browser available on Windows, Mac OS X, Linux, and other platforms. It is based on Mozilla's rendering engine, which is known to be a very CSS-compliant browser.


About the XML/CSS examples in this tutorial

In this tutorial you will see many examples of CSS files. You can find all the files used in this tutorial in the file, x-xmlcss2-tutorial-files.zip (see Downloads). In this package, all files start with a prefix indicating the section that covers them and the order the examples appear within the section. For example, files from the first example in the third section are named starting with "eg_3_1".

Files with the .css extension are Cascading Stylesheets, and files with the .xml extension are sample XML documents that you can display using the CSS file with the same prefix, if one is present. Some of the XML files are not associated with a matching CSS file; for example, they may demonstrate embedded CSS. A few of the files use more specialized extensions such as .svg for SVG files.

I do list the example files in each panel, so you can easily locate and experiment with the examples as you take this tutorial.

1 of 9 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML
ArticleID=138497
TutorialTitle=Display XML with Cascading Stylesheets, Part 2: Use Cascading Stylesheets to display XML
publish-date=02252005
author1-email=uche.ogbuji@fourthought.com
author1-email-cc=dwxed@us.ibm.com

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.