Showing posts with label XSLT. Show all posts
Showing posts with label XSLT. Show all posts

Tuesday, October 31, 2006

Using CSS when displaying an XML document

When you view an XML document in a web-browser you see the XML tree structure.

But it is possible for you to format the display using CSS, but mostly you would be using XSLT to transform the document with.

Here is a small example of how you can use CSS formatting for an XML document.

CSS file
books {
background-color: #000000;
width: 40%;
}
book {
background-color: #FF0000;
display : block;
margin-bottom: 20px;
}
title, price {
display : block;
color: blue;
}


XML document
<?xml version="1.0" encoding="ISO8859-1" ?>
<?xml-stylesheet type="text/css" href="books.css">
<books>
<book>
<title>Lord of the rings</title>
<price>1.99</price>
</book>
<book>
<title>The davinci mystery</title>
<price>2.99</price>
</book>
</books>