]> Six methods to link style sheets to SGML documents

Six methods to link style sheets to SGML documents

Bert Bos (bert@let.rug.nl)

This report describes six methods to link style sheets to SGML documents if both are on the WWW. Three of the methods are HTML specific, the other three apply to all SGML documents (including HTML). None of them rely on a specific protocol, such as HTTP, but three of them require URLs.

Schematically:

                       HTML  SGML   URL   CSS non-CSS
      -----------------------------------------------
        I. <LINK>        X           X     X     X
       II. <STYLE>       X                 X     X
      III. PI            X     X     X     X     X
       IV. catalog       X     X     X     X     X
        V. multipart     X     X           X     X
       VI. STYLE attr.   X                 X
    

Glossary

DSSSL, DSSSL Lite, CSS, UA, user, author, HTML, [...]

Style sheet application

For the purposes of this report, a style sheet is an instruction for formatting an SGML document. The style sheet can be in one or more separate files, or it can be inline in the document (as in II and VI below).

The style sheet is written in a language such as DSSSL, DSSSL Lite or CSS. When a UA uses a style sheet to format a document, one says that the style sheet `is applied to' the document.

A single document may have several associated style sheets and a user can even apply other style sheets that are not associated with it by the author.

All style sheets must have a title to distinguish them from each other and to help the user select the one to apply (if the UA allows selection). Two style sheets with the same title are considered parts of a single style sheet. How they are combined depends on the the style language. E.g., CSS has a well-defined `cascading' mechanism.

If the title is omitted (in I or II below) or if the title is `default' (in III, IV or V below), the style sheets is to be considered the default style. A typical UA will apply this style in the absence of any user preferences.

Special styles for HTML & CSS

If such a default style is written in CSS and the document is in HTML, then the UA is required to insert a partial style of its own, to which the default style is added. This partial style conforms to the recommended rendering that is described in the HTML standard and it helps to keep style sheets short. Appendix A expresses this partial style in CSS.

I. The LINK element with REL=STYLESHEET


HTML or SGML: HTML
uses URLs: yes
CSS only: no
status: deprecated


HTML allows LINK elements in the HEAD, to create hyperlinks where the source anchor is the whole document (as opposed to A, where the source is just a few words). Although a style cannot really be considered the target of a hyperlink, people have been using the LINK element for associating a style sheet with a document. The syntax is like this:

<LINK REL=STYLESHEET [TITLE="..."] HREF="...url...">=

Example:

<LINK REL=STYLESHEET TITLE="Large letters" HREF="large.=
css">

The title is optional (but not meaningless, see `style sheet application' above. The HREF must hold a URL.

This method is mentioned here, because it has been in use experimentally in some browsers. Its use is not recommended however, not only because LINK should be reserved for hyperlinks, but also becasue the link to the style sheet is only found when part of the document has possibly already been formatted.

II. The STYLE element


HTML or SGML: HTML
uses URL: no
CSS only: no
status: deprecated


The STYLE element has been suggested for HTML 3.0 and some browsers experimentally implement it. It can only occur in the HEAD. Its SGML definition is:

<!element style - - rcdata>
<!attlist style
    title cdata #implied
    notation cdata #required>

or in template form:

<STYLE [TITLE="..."] NOTATION="...">
 .. style sheet...
</STYLE>

Example:

<STYLE NOTATION=CSS>
H1 { font = 20pt/24pt helvetica bold }
EM { text-decoration = under }
</STYLE> 

[The possible values for `notation' are yet to be defined: Internet media types?]

See `style sheet application' above. for the meaning of the title.

Like the LINK element, the STYLE element is not recommended, because it causes the style sheet to occur too late in the document.

III. Processing instructions


HTML or SGML: SGML
uses URL: yes
CSS only: no
status: recommended


This method works for all SGML document, not only for HTML. The method is due to SoftQuad Inc. and Synex AB, who first used it in their Panorama software.

A style sheet is linked to a document by means of a processing instruction (PI) in the document's DTD subset, or, if the document comes with a private DTD, in the DTD. The syntax is as follows:

<?stylespec "...title..." "...url...">

Example:

<!doctype html public "-//IETF//DTD HTML//EN" [
<?stylespec "Punk style" "punk.css">
]>

If the doctype declaration refers to an external DTD (through a PUBLIC or SYSTEM identifier), the PI may also occur in that DTD. But note that you cannot add a PI to a DTD without giving it a new PUBLIC or SYSTEM identifier. If you don't, the UA could get a DTD with the same name but without the PIs from elsewhere.

In this syntax, the title is required, but the special title `default' (lowercase) has the same effect as an omitted title in I or II above.

IV. Catalog file


HTML or SGML: SGML
uses URL: yes
CSS only: no
status: recommended


The catalog file is is a file the format of which is defined by SGML Open Technical Report 9401. Its basic function is to translate punlic identifiers to system identifiers (in this case: URLs). The MIMESGML working group has proposed an addition to the catalog syntax, to allow style sheets to be included in it as well (see draft-ietf-mimesgml-exch-00.txt). A line of the following form must be added to a catalog file:

=
SEMANTICS  "...title..."  "...type..."  "...url..."

Example:

SEMANTICS  "Neon colors" "DSSSL" "neocol.sty"

Like in III above, the special title `default' may be used. The `type' is the name of the language in which the style sheet is written, such as `DSSSL' or `CSS'. (The draft isn't very clear on the possible values.)

An author wishing to use a catalog file to associate style sheets with a document, should create a file with lines like the one above and give it a relative URL `catalog' (lowercase), where the URL is relative to the base URL o the document. The UA will try to retrieve the catalog before formatting.

V. Multipart/related media type


HTML or SGML: SGML
uses URL: no
CSS only: no
status: recommended


This method can be seen as an optimisation of the catalog method above, for clients and servers that mutually agree to use it. The format is being proposed by the MIMESGML working group (see draft-ietf-mimesgml-related-02.txt). The proposal for style sheets in a catalog file, as mentioned under IV above, contains examples of its use for SGML, see draft-ietf-mimesgml-exch-00.txt

The multipart/related media type can be used for sending an SGML document and its related files (DTD, style sheet, etc.) in a single file, thus saving on the number of queries that have to pass between client and server.

VI. The STYLE attribute


HTML or SGML: HTML
uses URL: no
CSS only: yes
status: deprecated


In this method, most HTML elements geta new attribute called STYLE, the value of which is a sequence of properties in CSS notation. For example:

<H1 STYLE="text-color=green, font-size=24pt">
A huge, green title</H1>

See the CSS draft for the proposed syntax of the list of properties. The properties apply only to the element in which they are defined, and through normal inheritance to the child elements. The properties override any other properties that may apply to this element (from external style sheets), except for those that are marked `!important' or `!legal'.

Use of this method is not recommended, because it is too specific to HTML and CSS and requires the formatter to have special routines for HTML only. It also limits the style of an element to a single layout, which may not work on all output media.

Appendix A: the base style for HTML

If an HTML document has an associated `default' style (as described in `style sheet application' above.), and that style is written in CSS, then the lowest level of the style sheet cascade must be inserted by the UA and it must be equivalent to the style sheet below. Cascading is described in the CSS draft

H1  { font-size-index = xx-large, font-weight = bold,
      break-before = block, break-after = block }
H2  { font-size-index = x-large, font-weight = bold,
      break-before = block, break-after = block }
H3  { font-size-index = large, font-weight = bold,
      break-before = block, break-after = block }
 ..
B   { font-weight = bold }
EM  { font-style = italic }  -- UA dependent --
 ..