Edit online

Associating a Stylesheet with an XML Document

The rendering of an XML document in the Author mode is driven by a CSS stylesheet that conforms to the version 2.1 of the CSS specification from the W3C consortium. Some CSS 3 features, such as namespaces and custom extensions, of the CSS specification are also supported. Oxygen XML Editor also supports stylesheets coded with the LESS dynamic stylesheet language.

There are several methods for associating a stylesheet (CSS or LESS) with an XML document:
  1. Insert the xml-stylesheet processing instruction with the type attribute at the beginning of the XML document. If you do not want to alter your XML documents, you should create a new document type (framework).
    CSS example:
    <?xml-stylesheet type="text/css" href="test.css"?>
    LESS example:
    <?xml-stylesheet type="text/css" href="test.less"?> 
    Note: XHTML documents need a link element, with the href and type attributes in the head child element, as specified in the W3C stylesheet specification. XHTML example:
    <link href="/style/screen.css" rel="stylesheet" type="text/css"/>
    Tip: You can also insert the xml-stylesheet processing instruction by using the Associate XSLT/CSS Stylesheet action that is available on the toolbar or in the Document > XML Document menu.
  2. Add a new CSS or LESS file to a framework (document type). To do so, open the Preferences dialog box (Options > Preferences) and go to Document Type Association. Edit the appropriate framework, open the Author tab, then the CSS subtab. Press the New button to add a new CSS or LESS file.
    Note: The built-in frameworks are read-only, so you need to Extend or Duplicate them to configure them as custom frameworks.

If a document has no CSS association or the referenced stylesheet files cannot be loaded, a default one is used. A warning message is also displayed at the beginning of the document, presenting the reason why the CSS cannot be loaded.

Figure 1: Document with no CSS association default rendering

For information about associating a CSS to a framework (document type), see Customizing Author Mode Using CSS Files Associated with a Framework.