The presentation of this document has been augmented to identify changes from a previous version. Three kinds of changes are highlighted: new, added text, changed text, and deleted text.


W3C

Associating Style Sheets with XML documents 1.0 (Second Edition)

Editor's Draft 22 March 2010

This version:
http://www.w3.org/XML/2010/03/xml-stylesheet/
Previous versions:
http://www.w3.org/XML/2009/12/xml-stylesheet/ 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.

Editorial note: HST2010-02-24
Addresses kay-1

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. A more detailed description of the changes from the first edition is in B Changes since the first edition. 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.intended for review by the XML Core WG. It contains agreed dispositions of all issues as of the date of publication. Substantive (as opposed to low-level editorial) changes are preceded by an ednote referring to the particular issue addressed thereby.

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

Appendices

A References
B Changes since the first edition


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.

Editorial note: HST2010-02-24
Addresses holman-1
xml-stylesheet processing instructions and their pseudo-attributes are intended for use by document authors to provide links to and information about one or more stylesheets, as described in 4 The xml-stylesheet processing instruction, which are available to be applied to the containing document.

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.

Note:

Editorial note: HST2010-02-24
Addresses holman-1
The details of how conforming xml-stylesheet processors exploit the information contained in xml-stylesheet processing instructions are out of scope for this document, as they may reasonably vary from processor to processor.

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 CharRefs and PredefEntityRefs are replaced with the characters they representwith the modifications specified below — constitutes the value of the corresponding pseudo-attribute.]

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.

Editorial note: HST2010-02-24
Addresses taylor-3

If the parsing result is not an error, then it is the set of pseudo-attributes represented when the given string is matched by the PseudoAtts production.

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'sit is 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.

Editorial note: HST2010-02-24
Addresses kay-4

For details on how this is managed in XSLT, see 3.11 Embedded Stylesheet Modules in [XSLT].

type

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

Note:

Editorial note: HST2010-02-24
Addresses kay-2

Syntactic conformance to the production in RFC 2616 is all that is required by the above. This specification imposes no requirements with respect to the status of the types used. Some unregistered (as of the publication of this specification) media types, such as text/xsl, are well-supported by existing implementations, whereas some registered media types, such as application/xslt+xml, are not.

Editorial note: HST2010-02-24
Agreed on 2010-03-10 telcon, parallel to change for kay-3 below wrt charset
The value is advisory in that it is intended to be used by an application only when no other source of media type information becomes available during retrieval of the stylesheet itself.

title
Editorial note: HST2010-02-24
Addresses 7th para. of taylor-1

Gives the title of the referenced style sheet in a style sheet set. If specified, documents may use any string as No constraints beyond those of the PseudoAttValue production are placed on 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]

Editorial note: HST2010-02-24
Addresses kay-3
The value is advisory in that it is intended to be used by an application only when no other source of encoding information becomes available during retrieval of the stylesheet itself, either explicitly via an HTTP header, or implicitly via its media type, as in the case of XML documents.

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.

Editorial note: HST2010-02-24
Addresses holman-2 and taylor-4

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 create associations that occur before the associations specified by the xml-stylesheet processing instructions. The application is responsible for taking all associations and determining how, if at all, their order affects its processing.

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/.)
XSLT
(non-normative) XSL Transformations (XSLT) Version 2.0, M. Kay. W3C, January 2007. (See http://www.w3.org/TR/xslt20/.)

B Changes since the first edition

Editorial note: HST2010-02-24
Addresses kay-1

This appendix is non-normative

The first edition of this specification was admirably brief, but at the same time left many details unstated. This second edition aims to fill the gaps left in the first edition, while restructuring the presentation to provide for independent citation and re-use of the pseudo-attribute construct.

Neither the syntax nor the semantics of the xml-stylesheet processing instructions have been changed, beyond the restructuring just mentioned. Conformance constraints on processors have been eased slightly, in that xml-stylesheet processing instructions occurring within the internal or external subset may be ignored.

The following list identifies the major changes which have been made:

  • Provided definitions for a number of terms used but not defined in the first edition;

  • Added a conformance section, distinguishing between processor and document conformance, all of which was implicit in the first edition;

  • Identified a number of error cases, which were implicit in the first edition's appeal to the parallel with element start tag processing, and specified expected processor behaviour;

  • In recognition of deployed processor behaviour, allowed xml-stylesheet processing instructions to be ignored unless they are among the [children] of the document information item;

  • Added a number of references, but removed the explicit dependence on the HTML 4.0 specification by adding descriptions of the meanings of each of the pseudo-attributes consistent with their HTML 4.0 use but brought up-to-date;

  • Removed the (non-normative) Rationale section, as it contained a number of out-of-date assumptions;

  • Made the type pseudo-attribute optional, as agreed by existing erratum.