Using CSSDisplay XML


By using CSS (Cascading Style Sheets), you can add display information to XML documents.


Display your XML with CSS?

It is possible to use CSS to format XML documents.

The following example shows how to use a CSS style sheet to format an XML document:

Look at this XML file:CD Catalog

Then look at this style sheet:CSS file

Finally, please view:CD catalog formatted with the CSS file

Below is a small part of the XML file. The second line links the XML file to the CSS file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="cd_catalog.css.html"?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR>
</CD>
.
.
.
</CATALOG>

Formatting XML with CSS is not a common approach.

W3C recommends using XSLT; see the next chapter.

Other Extensions