[This local archive copy mirrored from the canonical site: http://www.w3.org/TR/NOTE-xml-stylesheet.html; links may not have complete integrity, so use the canonical document at this URL if possible.]

W3CNOTE-xml-stylesheet-19980405

Associating stylesheets with XML documents

W3C Note 5 Apr 1998

This Version:
http://www.w3.org/TR/1998/NOTE-xml-stylesheet-19980405
Latest Version:
http://www.w3.org/TR/NOTE-xml-stylesheet
Author:
James Clark

Status of This Document

This document is a NOTE made available by the W3 Consortium for discussion only. This indicates no endorsement of its content, nor that the Consortium has, is, or will be allocating any resources to the issues addressed by the NOTE.

Comments should be sent to the author.

This document describes a mechanism for associating stylesheets with XML documents.


Stylesheets can be associated with an XML document by using a processing instruction whose target is xml:stylesheet. This processing instruction follows the behaviour of <LINK REL="stylesheet"> in HTML 4.0.

The xml:stylesheet processing instruction is allowed anywhere in the prolog of an XML document. The processing instruction can have pseudo-attributes href (required), type (required), title (optional), media (optional), charset (optional). The semantics are exactly as with <LINK REL="stylesheet"> in HTML 4.0. There is also an xml:alternate-stylesheet processing instruction which is equivalent to <LINK REL="alternate stylesheet">.

Here are some examples from HTML 4.0 with the corresponding processing instruction:

<LINK href="mystyle.css" rel="stylesheet" type="text/css">
<?xml:stylesheet href="mystyle.css" type="text/css"?>

<LINK href="mystyle.css" title="Compact" rel="stylesheet"
type="text/css">
<?xml:stylesheet href="mystyle.css" title="Compact" type="text/css"?>

<LINK href="mystyle.css" title="Medium" rel="alternate stylesheet"
type="text/css">
<?xml:alternate-stylesheet href="mystyle.css" title="Medium"
type="text/css"?>

Multiple processing instructions are also allowed with exactly the same semantics as with LINK REL="stylesheet". For example,

<LINK rel="alternate stylesheet" title="compact" href="small-base.css"
type="text/css">
<LINK rel="alternate stylesheet" title="compact" href="small-extras.css"
type="text/css">
<LINK rel="alternate stylesheet" title="big print" href="bigprint.css"
type="text/css">
<LINK rel="stylesheet" href="common.css" type="text/css">

would be equivalent to:

<?xml:alternate-stylesheet title="compact" href="small-base.css"
type="text/css"?>
<?xml:alternate-stylesheet title="compact" href="small-extras.css"
type="text/css"?>
<?xml:alternate-stylesheet title="big print" href="bigprint.css"
type="text/css"?>
<?xml:stylesheet href="common.css" type="text/css"?>