W3C

Associating Style Sheets with XML documents 1.0 (Second Edition)

Editor's Draft 4 December 2009

This version:
http://www.w3.org/XML/2009/12/xml-stylesheet/
Previous version:
http://www.w3.org/1999/06/REC-xml-stylesheet-19990629/
Editors:
James Clark (First Edition) <jjc@jclark.com>
Simon Pieters (Second Edition), Opera Software <simonp@opera.com>
Henry S. Thompson (Second Edition), W3C, University of Edinburgh <ht@w3.org>

This document is also available in these non-normative formats: XML.


Abstract

This document allows style sheets 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.

Status of this Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

This document is a product of the XML Core Working Group as part of the W3C XML Activity. The English version of this specification is the only normative version. However, for translations of this document, see http://www.w3.org/2003/03/Translations/byTechnology?technology=xml-stylesheet.

This second edition incorporates all known errata as of the publication date, clarifies several areas left unspecified in the earlier edition, and has been restructured to allow other specifications to reuse the rules for parsing pseudo-attributes from a string. This edition, once it becomes a Recommendation, will supersede the previous edition of 29 June 1999.

This current draft has no official status. It is submitted for general review by W3C members and the public at this time in anticipation of its being submitted as a Proposed Edited Recommendation (PER) at a future date.

Please submit any comments on this document to www-xml-stylesheet-comments@w3.org; public archives are available.

This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

Table of Contents

1 Introduction
2 Conformance requirements
3 Pseudo-attributes
4 The xml-stylesheet processing instruction

Appendix

A References


1 Introduction

(This section is non-normative.)

Authors might have particular intentions as to how user agents are to present the information contained in their XML documents. This specification provides a non-intrusive mechanism, using a processing instruction, to provide links to one or more style sheets, i.e. resources specifying the desired rendering in a designated language. User agents will use these resources to control presentation of XML.

Consider an XHTML document with style sheet associations using the link element:

<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>Example with link elements</title>
  <link rel="stylesheet" href="common.css"/>
  <link rel="stylesheet" href="default.css" title="Default style"/>
  <link rel="alternate stylesheet" href="alt.css" title="Alternative style"/>
  <link rel="stylesheet" href="single-col.css" media="all and (max-width: 30em)"/>
 </head>
 <body>
  ...
 </body>
</html>

This document could be written as follows, using xml-stylesheet processing instructions:

<?xml-stylesheet href="common.css"?>
<?xml-stylesheet href="default.css" title="Default style"?>
<?xml-stylesheet alternate="yes" href="alt.css" title="Alternative style"?>
<?xml-stylesheet href="single-col.css" media="all and (max-width: 30em)"?>
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>Example with xml-stylesheet processing instructions</title>
 </head>
 <body>
  ...
 </body>
</html>

2 Conformance requirements

All diagrams, examples, and notes in this specification are non-normative, as are all sections explicitly marked non-normative. Everything else in this specification is normative.

The key words must, must not, should, should not and may in the normative parts of this document are to be interpreted as described in RFC 2119. These words do not appear in all uppercase letters in this specification. [RFC2119]

The following conformance classes are defined by this specification:

Documents

A document is considered to be a conforming document if it satisfies all must-level criteria in this specification that apply to documents.

xml-stylesheet processors

XML defines an application as a software module which receives the information content of an XML document from an XML processor. [Definition: An xml-stylesheet processor is such an application which processes XML processing instructions in accordance with this specification.] [XML]

An xml-stylesheet processor may be part of a larger XML application, or may function independently. In either case, [Definition: an application is the consumer of the pseudo-attribute analysis defined in this specification.]

An xml-stylesheet processor is considered to be a conforming xml-stylesheet processor if it satisfies all must-level criteria in this specification that apply to xml-stylesheet processors. xml-stylesheet processors do not have to check or enforce any of the constraints on documents.

This specification is defined with reference to the vocabulary for XML provided by the XML Information Set. [INFOSET]

The productions in this specification use the same notation as used in the XML specification. Tokens in the grammar that are not defined in this specification are defined in the XML specification. [XML]

3 Pseudo-attributes

[Definition: The rules for parsing pseudo-attributes from a string are given in this section.]

[Definition: The parsing result is either a set of pseudo-attributes or an error.]

If the given string is not matched by the PseudoAtts production, the parsing result is an error.

Productions for strings with pseudo-attributes
[1a]   PseudoAtts   ::=    PseudoAtt? (S PseudoAtt)* S?
[2]   PseudoAtt   ::=   Name S? "=" S? PseudoAttValue
[3]   PseudoAttValue   ::=   ('"' ([^"<&] | CharRef | PredefEntityRef)* '"' | "'" ([^'<&] | CharRef | PredefEntityRef)* "'")
[4]   PredefEntityRef   ::=   "&amp;" | "&lt;" | "&gt;" | "&quot;" | "&apos;"

[Definition: Each string matched by PseudoAtt in the PseudoAtts production represents a pseudo-attribute.] A pseudo-attribute has a name and a value.

[Definition: The string matched by Name in the PseudoAtt production constitutes the name of the corresponding pseudo-attribute.]

[Definition: The string matched by PseudoAttValue in the PseudoAtt production — after any CharRefs and PredefEntityRefs are replaced with the characters they represent — constitutes the value of the corresponding pseudo-attribute.] Each CharRef in PseudoAttValue is replaced with the character it represents according to XML. [XML] Each PredefEntityRef in PseudoAttValue is replaced with with U+0026 (&) if it is "&amp;", U+003C (<) if it is "&lt;", U+003E (>) if it is "&gt;", U+0022 (") if it is "&quot;" and U+0027 (') if it is "&apos;".

The parsing result is an error if the XML Legal Character well-formedness contraint is violated for any CharRef. [XML]

The parsing result is an error if there are more than one pseudo-attribute with the same name.

4 The xml-stylesheet processing instruction

[Definition: A processing instruction information item is said to be a potential xml-stylesheet processing instruction if it has the [target] property xml-stylesheet and it either is in the [children] property of a document information item and appears before the element information item of the document information item's [children] property, or it appears in the [children] property of a document type declaration information item.]

For potential xml-stylesheet processing instructions that are in the [children] property of a document information item, xml-stylesheet processors must report to the application the parsing result of invoking the rules for parsing pseudo-attributes from a string, using the processing instruction information item's [content] property as the string.

For potential xml-stylesheet processing instructions that are in the [children] property of a document type declaration information item, xml-stylesheet processors may report to the application the parsing result of invoking the rules for parsing pseudo-attributes from a string, using the processing instruction information item's [content] property as the string. [Definition: If it's not reported to the application, the processing instruction information item is said to be ignored.]

Note:

Since non-validating XML processors are not required to read parameter entities or the external subset, it is possible that processing instructions that appear in parameter entities or the external subset will not be present in the document type declaration information item's [children] property. [XML]

[Definition: A potential xml-stylesheet processing instruction is said to be an xml-stylesheet processing instruction if the parsing result is not an error when invoking the rules for parsing pseudo-attributes from a string, using the processing instruction information item's [content] property as the string.]

Documents must not use processing instruction information items with the [target] property xml-stylesheet if they are not xml-stylesheet processing instructions.

Documents should not use xml-stylesheet processing instructions that are in the [children] property of a document type declaration information item.

An xml-stylesheet processing instruction will match the following production:

Production for xml-stylesheet processing instruction
[1]   StyleSheetPI   ::=   "<?xml-stylesheet" (S PseudoAtts)? - (Char* "?>" Char*) "?>"

Documents may specify the following pseudo-attributes on xml-stylesheet processing instructions, unless otherwise stated:

href

Gives the address of the referenced style sheet. Documents must specify this pseudo-attribute. Documents must set the value to a string that matches the grammar for <IRI-reference> given in RFC 3987. [RFC3987]

Note:

It is possible to associate a style sheet that is in the same document as the xml-stylesheet processing instruction by using just a fragment identifier in the href pseudo-attribute.

type

Gives an advisory type of the referenced style sheet. If specified, documents must set the value to a string that matches the media-type token defined in section 3.7 "Media Types" of RFC 2616. [RFC2616]

title

Gives the title of the referenced style sheet in a style sheet set. If specified, documents may use any string as the value.

media

Gives the media for which the referenced style sheet applies. If specified, documents must set the value to a string that matches the media_query_list production of the Media Queries specification. [MQ]

charset

Gives an advisory character encoding for the referenced style sheet. If specified, documents must set the value to a valid character encoding name, which must be the name or alias labeled as "preferred MIME name" in the IANA Character Sets registry, if there is one, or the encoding's name, if none of the aliases are so labeled. [IANACHARSET]

alternate

If the value is "yes", it indicates that the referenced style sheet is an alternative style sheet, and documents must also specify the title pseudo-attribute with a non-empty value. If specified, documents must set the value to either "yes" or "no".

Documents must not specify other pseudo-attributes on xml-stylesheet processing instructions.

Any links to style sheets that are specified externally to the document (e.g. Link headers in some versions of HTTP [RFC2068]) are considered to occur before the associations specified by the xml-stylesheet processing instructions.

A References

References are normative unless marked "non-normative".

IANACHARSET
Character Sets. IANA, May 2007. (See http://www.iana.org/assignments/character-sets.)
INFOSET
XML Information Set, J. Cowan, R. Tobin. W3C, February 2004. (See http://www.w3.org/TR/xml-infoset/.)
MQ
Media Queries, H. Lie, T. Çelik, D. Glazman, A. van Kesteren. W3C, April 2009. (See http://www.w3.org/TR/css3-mediaqueries/.)
RFC2068
(Non-normative.) Hypertext Transfer Protocol — HTTP/1.1, R. Fielding, J. Gettys, J. Mogul, H. Frystyk, T. Berners-Lee. IETF, June 1997. (See http://www.ietf.org/rfc/rfc2068.txt.)
RFC2119
Key words for use in RFCs to Indicate Requirement Levels, S. Bradner. IETF, March 1997. (See http://www.ietf.org/rfc/rfc2119.txt.)
RFC2616
Hypertext Transfer Protocol — HTTP/1.1, R. Fielding, J. Gettys, J. Mogul, H. Frystyk, L. Masinter, P. Leach, T. Berners-Lee. IETF, June 1999. (See http://www.ietf.org/rfc/rfc2616.txt.)
RFC3987
Internationalized Resource Identifiers (IRIs), M. Dürst, M. Suignard. IETF, January 2005. (See http://www.ietf.org/rfc/rfc3987.txt.)
XML
Extensible Markup Language, T. Bray, J. Paoli, C. Sperberg-McQueen, E. Maler, F. Yergeau. W3C, November 2008. (See http://www.w3.org/TR/xml/.)