XML technologies / XML / XML in a Nutshell / Cascading Style Sheets (CSS) / Associating stylesheets with XML documents

(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)

CSS stylesheets are intended primarily for web pages. Browsers find a document’s stylesheet by looking for xml-stylesheet processing instructions in the XML document’s prolog. This processing instruction (Processing Instruction) should have a pseudo-attribute type with value text/css and a pseudo-attribute href, whose value is an absolute or relative URL locating the stylesheet document. This processing instruction associates the stylesheet in the code example A CSS stylesheet for recipes (rezept.css) with the file in the code example Marjorie Anderson’s recipe for Southern Corn Bread (cornbread.xml) if both are in the same directory:

 <?xml-stylesheet type="text/css" href="rezept.css"?> 

Including the required pseudo-attributes type and href the processing instruction xml-stylesheet can have up to six pseudo-attributes:

For example, this group of xml-stylesheet processing instructions could be placed in the recipe document’s prolog to make it accessible to a broader range of devices:

<?xml-stylesheet type="text/css" href="rezept.css" media="screen" alternate="no" title="Für Webbrowser" charset="US-ASCII"?>
<?xml-stylesheet type="text/css" href="druckbares_rezept.css" media="print" alternate="no" title="Für den Druck" charset="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="rezept_gross.css" media="projection" alternate="no" title="Für Präsentationen" charset="UTF-8"?>
<?xml-stylesheet type="text/css" href="tty_rezept.css" media="tty" alternate="no" title="Für Lynx" charset="US-ASCII"?>
<?xml-stylesheet type="text/css" href="rezept_klein.css" media="handheld" alternate="no" title="Für Palm Pilots" charset="US-ASCII"?>

  

 

 

 

back to top