2007-04-03
Yi-hong Chang,
<yhchang@iis.sinica.edu.tw>
Institute of Information Science
Academia Sinica, Taipei, Taiwan
XML Document is a Structured Data Document.
There is not any defination about how to present an XML document in the XML specification.
How an XML document is presented is depending on the application.
Examples:
To present an XML Document, one should use "stylesheets", eg. XSL or CSS.
W3C CSS Home: http://www.w3.org/Style/CSS/
History:
Other versions:
CSS is the typical method to present a HTML (XHTML) document.
<?xml version="1,0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<style type="text/css">
body {background-color:silver}
h1 {color:red}
h2 {color:teal}
</style>
</head>
<body>
<h1>Header 1</h1>
<h2>header 2</h2>
<p>paragraph</p>
</body>
</html>
h1 selector { color property | : |declaration red value | }
result: XHTML with CSS
However, CSS is not limited to XHTML, it is also common to use CSS with an XML document,
e.g. SVG (Sector Vector Graphic).
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">
<svg xmlns="http://www.w3.org/2000/svg">
<defs>
<style type="text/css"><![CDATA[
text {
font-size:30px;
font-family:Arial;
font-weight:bold;
}
]]></style>
</defs>
<circle cx="100px" cy="50px" r="50" fill="#00f"/>
<text x="100" y="60" text-anchor="middle" fill="red">TEXT</text>
</svg>
This is how a SVG-enable application renders the above SVG.
It is also common to use CSS with an normal XML document.
A XML document...
<?xml version="1.0"?> <?xml-stylesheet type="text/css" href="XmlWithCss.css"?> <faq> <body xml:lang="en"> <qna id='a1'> <q>A.1. What is a FAQ?</q> <a>A FAQ is the nickname for a "Frequently Asked Questions" document.</a> </qna> <qna id='a2'> <q>A.2. Question 2</q> <a>Answer</a> </qna> </body> </faq>
with this CSS...
q { display:block; font-weight:bold; font-size: 1.5em; color:blue;} a { display:block; font-size:1em; color:green;}
this result is : XHTML with CSS
The difference between using CSS with XML, XHTML, SVG is that
XHTML and SVG has a default styles defination.
For an "XHTML-or-SVG-enable-application", e.g. Opera, It knows how to present an XHTML or SVG document.
<i> a HTML Italic Element.</i> <u> a HTML Underline Element.</u>
CSS Core Syntax (simplified)
stylesheet: statement*; statement: ruleset | at-rule; ruleset: selector? '{' S* declaration? [';' S* declaration?]* '}' S*; declaration: property S* ':' S* value; at-rule : ATKEYWORD S* any* [ block | ';' S* ];
A CSS ruleset example
header {color:red; background:white}
The CSS requires parsing XML Document as a Tree.
<?xml version="1.0"?> <?xml-stylesheet type="text/css" href="XmlWithCss.css"?> <faq> <body xml:lang="en"> <section> <qna id='a1'> <q>A.1. What is a FAQ?</q> <a>A FAQ is the nickname for a "Frequently Asked Questions" document.</a> </qna> </section> <qna id='a2'> <q>A.2. Question 2</q> <a>Answer</a> </qna> </body> </faq>
Child/descendant elements will inherite SOME values of properties defined in the parent element.
body {color:red; font-size:10px} q { font-size: 120%}
the result is:
body {color:red, font-size:10px} q {color:red, font-size:12px}
ruleset: selector? '{' S* declaration? [';' S* declaration?]* '}' S*; declaration: property S* ':' S* value;
universal selector, ANY elements.
* {color:red}
Element Selector
qna {color:red}
Element Selector
section q {color:red}
Element Selector
section>qna {color:red}
Element Selector
section+qna {color:red}
Attribute Selector
q[title]
Attribute Selector
q[title="a"]
Attribute Selector
q[title~="b"]
Attribute Selector
body[xml:lang|="en"]
Attribute Selector
.red {color:red}
Attribute Selector
#a1 {color:red}
Psedo-classes Selector
ul > li:first-child {color:red} ul > li:first-child + li +li {color:green}
<ul> <li>TRC</li> <li>Evirt</li> <li>Andrea</li> </ul>
Psedo-classes Selector
a:link {color:red} a:visited {color:green}
<a href="http://www.w3.org">www.w3.org</a>
Psedo-classes Selector
a:hover {color:orange} a:active {color:olive} a:focus {color:yellow}
<a href="http://www.w3.org">www.w3.org</a>
Psedo-elements Selector
p:first-line {color:orange}
p:first-letter {color:red}
The main town in the western Solomons, Gizo,
was hit by waves several metres high that swamped buildings and washed people out to sea, officials said.
Psedo-elements Selector
p:before{ content:"[before]"} p:after{ content:"[after]"}
The main town in the western Solomons, Gizo,
was hit by waves several metres high that swamped buildings and washed people out to sea, officials said.
Combining and Grouping
ul > li:first-child {color:red}
<p>Humans</p>
<ul>
<li>TRC</li>
<li>Evirt</li>
<li>Andrea</li>
</ul>
p, li {color:red}
<p>Humans</p> <ul> <li>TRC</li> <li>Evirt</li> <li>Andrea</li> </ul>
Keywords: Keywords must not be placed between quotes ("..." or '...').
width: auto; border: none; background: red; font-size: small;
Units
font-size: 12px; font-size: 1em; font-size: 1mm; font-size: 120%;
body { background: url("http://www.example.com/pinkish.png") }
margin-top margin-right margin-bottom margin-left
margin: margin-top margin-right margin-bottom margin-left
Every element can be seen as a box which contain it's child box.
<?xml version="1.0"?> <?xml-stylesheet type="text/css" href="XmlWithCss.css"?> <faq> <body xml:lang="en"> <section> <qna id='a1'> <q>A.1. What is a FAQ?</q> <a>A FAQ is the nickname for a "Frequently Asked Questions" document.</a> </qna> </section> <qna id='a2'> <q>A.2. Question 2</q> <a>Answer</a> </qna> </body> </faq>
A box has the following features:
box.box1 { border-top: thin solid blue; border-right: medium dotted green; border-bottom: thick dashed red; border-left: 2px double olive; padding:10px 20px 30px 40px; } content.content1{ border: 1px solid black; }
<box class="box1"> <content class="content1">block</content> </box>
The properties for the actual visual effect of a box are "display", "position", "float", and etc.
display:block; display:inline; display:none; display:run-in;
Block 1
Block 2 with a inline box.
and...
position: relative position: absolute
float: left|right clear: left|right|both
<img style="float:left;width:80px" src="floatimg.jpg"/> <img style="float:right;width:80px" src="floatimg.jpg"/><p> At least 12 people have died in the Solomon Islands after a tsunami swept ashore following a strong undersea earthquake in the South Pacific.The main town in the western Solomons, Gizo, was hit by waves several metres high that swamped buildings and washed people out to sea, officials said.</p> <br style="clear:both"/>
At least 12 people have died in the Solomon Islands after a tsunami swept ashore following a strong undersea earthquake in the South Pacific.The main town in the western Solomons, Gizo, was hit by waves several metres high that swamped buildings and washed people out to sea, officials said.
and...
<img style="border:1px solid #333;width:80px" src="floatimg.jpg"/> <img style="border:1px solid #333;width:200px;height:50px" src="floatimg.jpg"/>
<span style="color:red">RED</span>
body { background: white url("pendant.png"); background-repeat: repeat-y; background-position: center; }
p { font-family: Arial; font-style: italic; font-variant: normal; font-weight: bolder; font-size: small; line-height: 150%; } p { font: 12px/14px sans-serif } p { font: 80% sans-serif } p { font: x-large/110% "New Century Schoolbook", serif } p { font: bold italic large Palatino, serif } p { font: normal small-caps 120%/120% fantasy }
p { text-indent: 3em; text-align: center; text-decoration:underline; }
At least 12 people have died in the Solomon Islands after a tsunami swept ashore following a strong undersea earthquake in the South Pacific.The main town in the western Solomons, Gizo, was hit by waves several metres high that swamped buildings and washed people out to sea, officials said.
pointer crosshair move help
As in the Inheritance section says: some values are inherited. Which means that some other values are NOT inherited
body{ margin-top:100px} header{}
CSS is cascading
At-rules start with an at-keyword, an '@' character followed immediately by an identifier:
@import "subs.css"; @import "print-main.css" print; @media print { body { font-size: 10pt } }
illegal:
@import "subs.css"; h1 { color: blue } @import "list.css";
One of the most important features of style sheets is that they specify how a document is to be presented on different media: on the screen, on paper, with a speech synthesizer, with a braille device, etc.
<?xml version="1.0"> <?xml-stylesheet href="my-style1.css" type="text/css" media="print"?> <?xml-stylesheet href="my-style2.css" type="text/css" media="screen"?> <root> ...
...
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<style type="text/css">
body {background-color:silver}
h1 {color:red}
h2 {color:teal}
</style>
</head>
<body>
...
<p style="color:red;font-size:x-large">paragraph<p> <span style="color:red;font-size:x-large">some words<span> <div style="background:#ccc">division<div>
... <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <link href="mystyle.css" rel="stylesheet" type="text/css" media="screen"/> <link href="mystyle.css" rel="stylesheet" type="text/css" media="screen, projection, print"/> </head> <body> ...
<?xml version="1.0"> <?xml-stylesheet href="my-style1.css" type="text/css" media="print"?> <?xml-stylesheet href="my-style2.css" type="text/css" media="screen"?> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> ...