Associating stylesheets with XML documents

Version 1.0

World Wide Web Consortium Working Draft 1-October-1998

This version


Latest version



James Clark ()

Copyright  ©  1998 W3C (MIT, INRIA, Keio), All Rights Reserved. W3C liability, trademark, document use and software licensing rules apply.

Status of this document

This is a W3C Working Draft for review by W3C members and other interested parties. While we do not anticipate substantial changes to the mechanism described in this document, we still caution that further changes are possible and therefore we recommend that only experimental software or software that can be easily field-upgraded be implemented to this specification at this time. We also plan in a future specification to provide additional mechanisms for associating stylesheets with XML documents.

This is a draft document and may be updated, replaced, or obsoleted by other documents at any time. The XML Syntax Working Group will not allow early implementation to constrain its ability to make changes to this specification prior to final release. It is inappropriate to use W3C Working Drafts as reference material or to cite them as other than "work in progress". A list of current W3C working drafts can be found at http://www.w3.org/TR.


This document allows a stylesheet to be associated with an XML document by including one or more processing instructions with a target of xml-stylesheet in the document's prolog.

Table of Contents

1. The xml-stylesheet processing instruction
2. References

1. The xml-stylesheet processing instruction

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

The xml-stylesheet processing instruction is parsed in the same way as a start-tag, with the exception that entities other than predefined entities must not be referenced.

The following grammar is given using the same notation as the grammar in the XML Recommendation[XML10]. Symbols in the grammar that are not defined here are defined in the XML Recommendation.

xml-stylesheet processing instruction

[1] StylesheetPI ::= '<?xml-stylesheet' (S PseudoAtt)* S '?>'
[2] PseudoAtt ::= Name S '=' S PseudoAttValue
[3] PseudoAttValue ::= '"' ([^"<&] | CharRef | PredefEntityRef)* '"'
      | "'" ([^'<&] | CharRef | PredefEntityRef)* "'"
[4] PredefEntityRef ::= '&amp;' | '&lt;' | '&gt;' | '&quot;' | '&apos;'

The xml-stylesheet processing instruction is allowed anywhere in the prolog of an XML document. The syntax of XML constrains where processing instructions are allowed in the prolog; the xml-stylesheet processing instruction is subject to these constraints in the same way as any other processing instruction.

The following pseudo attributes are defined

alternate (yes|no) "no"

The semantics of the pseudo-attributes are exactly as with <LINK REL="stylesheet"> in HTML 4.0, with the exception of the alternate pseudo-attribute. If alternate="yes" is specified, then the processing instruction has the semantics of <LINK REL="alternate stylesheet"> instead of <LINK REL="stylesheet">.

HTTP[RFC2068] allows stylesheets to be associated with XML documents by means of the Link header. Any links specified by HTTP Link headers are considered to occur before the links specified by the xml-stylesheet processing instructions. This is the same as in HTML 4.0.

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"
<?xml-stylesheet href="mystyle.css" title="Compact" type="text/css"?>

<LINK href="mystyle.css" title="Medium" rel="alternate stylesheet"
<?xml-stylesheet alternate="yes" href="mystyle.css" title="Medium"

Multiple xml-stylesheet 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"
<LINK rel="alternate stylesheet" title="compact" href="small-extras.css"
<LINK rel="alternate stylesheet" title="big print" href="bigprint.css"
<LINK rel="stylesheet" href="common.css" type="text/css">

would be equivalent to:

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

2. References

World Wide Web Consortium. HTML 4.0 Specification. W3C Recommendation. See http://www.w3.org/TR/REC-html40
R. Fielding, J. Gettys, J. Mogul, H. Frystyk Nielsen, and T. Berners-Lee. Hypertext Transfer Protocol -- HTTP/1.1.. IETF RFC 2068. See http://ds.internic.net/rfc/rfc2068.txt.
World Wide Web Consortium. Extensible Markup Language (XML) 1.0. W3C Recommendation. See http://www.w3.org/TR/1998/REC-xml-19980210