Table of Contents

CSL 0.8.1 Syntax Overview

This page describes the syntax of version 0.8.1 of the Citation Style Language (CSL), including information specific to Zotero. An additional source of documentation is the CSL 0.8.1 schema, which is written in RELAX NG Compact and can be used for style validation.

Pointers on how CSL styles can be created, modified, validated, shared and installed in Zotero can be found here, together with more background information about CSL.

CSL Style Structure

All CSL styles share the same basic structure: only five different XML elements can be nested directly in the style root element: info, citation, bibliography, macro and terms. The roles of each of these elements (described in more detail below) are:

Independent and Dependent Styles

Two main types of CSL styles exist: independent and dependent styles. An independent style contains a full style description, and includes at least the info and citation element. Unless it is a note-based style that lacks a bibliography, it also includes the bibliography element. The terms element and one or more macro elements are optional in independent styles. A dependent style, on the other hand, merely refers to an independent style, like an alias or shortcut. It only includes the info element. Dependent styles are used if multiple publications share a single style format. Each publication can thus have its own dependent style (with the info section describing the journal's metadata, e.g. the journal's name or ISSNs) with a corresponding entry in (for instance) the Zotero Style Repository, while only a single independent master style has to be maintained.

Note that dependent styles cannot be used to indicate changes compared to the master style. If there is any difference in formatting between two styles, however small, two separate CSL styles have to be created.

Preamble

Before the style element, each CSL style should include the XML declaration element, specifying the version of XML used as well as the character encoding. The style element itself carries a number of arguments:

An example of a preamble is shown below. For most styles only the value of class and default-locale will differ.

<?xml version="1.0" encoding="UTF-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" xml:lang="en" default-locale="fr-FR">

Info

The info section of a CSL style contains the style metadata, which does not affect the formatting of citations. Instead, the metadata makes it possible to host styles in style repositories, to allow users to subscribe to field-specific style collections, and to automatically update styles. An example of a filled-in info section is shown below, and is followed by a description of all possible elements.

<info>
 <title>My first style</title>
 <id>http://www.zotero.org/styles/my-style-name</id>
 <link href="http://www.zotero.org/styles/my-style-name"/>
 <author>
  <name>My name</name>
  <email>my-address@wherever.com</email>
  <uri>http://wherever.com/</uri>
 </author>
 <category term="author-date"/>
 <category term="zoology"/>
 <updated>2008-10-29T21:01:24+00:00</updated>
 <summary>My great new style format.</summary>
 <rights>This work is licensed under a Creative Commons
         Attribution-Share Alike 3.0 Unported License
         http://creativecommons.org/licenses/by-sa/3.0/</rights>
</info>

Many elements available in the info section are borrowed from the Atom Syndication Format:

Citation

The citation construct is a key part of the style, and describes how in-line citations should be formatted. Sometimes a citation will only be a simple number, in other cases a more elaborate citation is desired, as is the case for author-date styles. The basic structure of the citation construct is as follows:

<citation>
  <option />
  <layout>
    some layout
  </layout>
</citation>

The layout specifies what information should be included in the citation. Additional control is possible with a range of options, which will be discussed later. Already for the layout element itself some optional parameters can be set, the most common being a prefix, suffix and delimiter. The delimiter functions in distinguishing multiple items in a single citation. For instance

<layout prefix="(" suffix=")" delimiter="; ">

would result in a citation like “(item1;item2)”, where the contents of the layout element would describe how item1 and item2 should be formatted (e.g. as “(Doe 1999; Johnson 2002)”).

Bibliography

This is the second of the key parts, where the bibliography is formatted. It is very similar to the citations section.

<bibliography>
  <option .../>
  <layout>
    ...
  </layout>
</bibliography>

Again, a set of options to control some of the layout, then the layout itself.

Macros

A list of macro definitions is usually included between the info and citation sections. These are sort of like subroutines that can be called later in the description to make similar styles for parts. Effective use of macros is a key to making good styles. Ideally, in fact, the main layout sections for the citation and bibliography should be quite simple, and simply call a series of macros.

An example macro is

<macro name="editor-translator">
  <names variable="editor translator" prefix="(" suffix=")" delimiter=", ">
    <name and="symbol" initialize-with=". " delimiter=", "/>
    <label form="short" prefix=", " text-transform="capitalize" suffix="."/>
  </names>
</macro>

It is particularly crucial in author-date styles that rely on author names for sorting that one create a macro that can handle a wide variety of cases, including resources that do no include listed authors. Example:

<macro name="author">
  <names variable="author">
    <name name-as-sort-order="all" 
          and="symbol" 
          sort-separator=", " 
          initialize-with=". "
          delimiter=", " 
          delimiter-precedes-last="always"/>
    <label form="short" prefix=" (" suffix=".)" text-transform="capitalize"/>
    <substitute>
      <names variable="editor"/>
      <names variable="translator"/>
      <text macro="title"/>
    </substitute>
  </names>
</macro>

This example includes the logic that allows the formatter to gracefully adapt to a wide-range of resource types. Likewise, one could create a macro for titles like so:

  <macro name="title">
    <choose>
      <if type="book">
        <text variable="title" text-case="sentence" font-style="italic"/>
      </if>
      <else>
        <text variable="title" text-case="sentence"/>
      </else>
    </choose>
  </macro>

Note here that CSL reserves three types as generic fallbacks. In this case, for example, “book” is a generic fallback for all resources that have the characteristic that they are essentially self-contained items. So, for example, a music album will use this rule in the absence of any rules specific to its type.

Because of the value of macros and the potential to reuse them in different styles and automated software tools, it is recommended that you try to adapt common macro names, such as:

Terms

CSL provides a number of localized strings like “et al.”, “vol.”, and “edited by”. However, in some cases you might want to change these preset strings. Specifying terms via the terms element allows you to do just that. Usually this element is included just below the info element. An example is shown below:

<terms>
  <locale xml:lang="en">
    <term name="editor" form="verb-short">ed. by</term>
    <term name="editor" form="short">
      <single>edtr</single>
      <multiple>edtrs</multiple>
    </term>
  </locale>
</terms>

A complete list of localized terms, together with their translations, can be found in the Zotero SVN repository.

Citation-Bibliography-Macro Syntax

Most of following syntax applies to the macro, citation and bibliography sections.

Options

Styles are partially configured by setting a number of options. Some of these options are available in both the citation and bibliography sections, while others are specific to one of the two sections. Below a description and example is given for each option.

Common options

These apply to both citation and bibliography sections.

<option name="et-al-min" value="6"/>
<option name="et-al-use-first" value="6"/>

Citation only options

<option name="et-al-subsequent-min" value="6"/>
<option name="et-al-subsequent-use-first" value="1"/>
<option name="disambiguate-add-year-suffix" value="true"/>
<option name="disambiguate-add-names" value="true"/>
<option name="disambiguate-add-givenname" value="true"/>

Bibliography only options

<option name="hanging-indent" value="true"/>
<option name="second-field-align" value="margin"/>
<option subsequent-author-substitute="some text"/>
<option name="entry-spacing" value="0"/>
<option name="line-spacing" value="2"/>

Sorting

The sorting order for in-text citation groups [e.g. (Doe 2001; Johnson 2003)], and for the bibliography can be set with the sort element, in which one or multiple sort keys can be specified. Sort keys can consist of either variables or macros, e.g.:

<citation>
  <sort>
    <key macro="author"/>
    <key variable="issued" sort="descending"/>
  </sort>
</citation>

In this example, citations are first sorted by the output of the author macro. Multiple entries that share the same author macro output are further sorted in reverse order by date of issue (if not specified, the value of the sort attribute is assumed to be “ascending”). Using macros instead of variables as sort keys is especially useful in case of substitutions (e.g., if no authors are specified, sort according to the translators/editors), or when sorting should be according to year instead of date of issue.

Variables

These are the variables that can be used in the layout. They can also be tested in the <if> syntax, and displayed with the <text variable=“title”> syntax. They map to various things in the zotero entries. Some of them are available in both short and long form.

Authors

These are the types of author that can be used in the layout. They can be displayed with the <names> syntax. They map to various things in the zotero entries. Some of them are available in both short and long form.

Author markup is done using the <names> and <name> directives. The names wraps the whole thing, and the name how to format an individual. The names also allows a <substitute> block to fill in with other syntax. For the <name> block, there are a number of options that can be specified, besides the generic formatting:

e.g.,

<names variable="author">
 <name form="short" and="symbol" delimiter=", " initialize-with=". "/>
</names>

The <substitute> comes into play if the named author variable is missing. It allows other things to be substituted. For instance

<names variable="author">
 <name name-as-sort-order="all" and="symbol" sort-separator=", " initialize-with=". "
    delimiter=", " delimiter-precedes-last="always"/>
 <label form="short" prefix=" (" suffix=".)" text-transform="capitalize"/>
 <substitute>
   <names variable="editor"/>
   <names variable="translator"/>
   <text macro="title"/>
 </substitute>
</names>

would fill in with the editor, translator or the title in that order.

Dates

There are various date fields that can be used. These are typically displayed with the <date> markup.

Dates are processed with the <date> and <date-part> markup. The <date> part is a wrapper around the block, and specifies the date you are working with. This usually encapsulates a sequence of <date-part> directives. The date as a whole can have the usual formatting directives. The <date-part> lets you format individual parts of the date. The parameters, apart from the usual formatting constructs, are

For example:

<date variable="issued" suffix=";">
   <date-part name="year" suffix=" "/>
   <date-part name="month" form="short" suffix=" "/>
   <date-part name="day"/>
</date>

Although a delimiter can be specified in the date part, it is used to separate multiple dates and not to separate parts of the date. Therefore prefix and suffix are important in the date-part.

Text

The <text> directive is the way to include text in the output from a variety of sources. For example:

<text variable="title" prefix=" Title: " form="short"/>

The first parameter can be one of:

Other parameters you can include are

You can also include any of the Formatting directives.

Formatting

The following formatting parameters for most elements specifying output.

For instance

<text variable="edition" prefix=" " suffix=" ed. "/>
<text term="retrieved" text-transform="capitalize" suffix=" "/>

Labels

Labels are used to add common text that may be dependent on the item. An example is the label for pages, which can be p. or pp. depending on the number of pages referenced. For instance

<group prefix=" (" suffix=")">
  <label variable="page" form="short" suffix=". "/>
  <text variable="page"/>
</group>

locator is the other variable commonly used. Label elements allow for the usual text formatting, the choice between different forms (short, long, etc.) and an option to include a trailing '.'. Labels can also be applied without a variable inside a <names> element. In this case, the label is the role label (e.g., “edited by”)

Groups

The group construct allows you to group together elements with a format applied to the whole group.

<group delimiter=": ">
 <text variable="publisher-place"/>
 <text variable="publisher"/>
</group>

The group is ignored if it contains no variables that exist in the document, even if it contains locale terms. A group can also represent semantic document components, as in:

<group class="container" prefix=". ">

Conditionals

Conditional information is tested with the <if> construct, which must be embedded in a <choose> block. There is an <else-if> and an <else> to allow multi-way choices. It is common in bibliographies to do different arrangements based on the type, as in

<choose>
  <if type="book">
    ...
  </if>
  <else-if type="chapter">
    ...
  </else-if>
  <else>
    ...
  </else>
</choose>

Things that can be tested are type's as above, variables (which includes authors and dates). Also are a few meta variables which include

Multiple variables can be tested as in

<if type="chapter book" match="any">

Item Types

Here is a list of Zotero item types which have a specific mapping (a complete table of item types and associated field mappings is available here). For example your CSL code must use “paper-conference” if you want to refer to the “Conference Paper” type. Note that some item types are not, at the moment, mapped (e.g.: encyclopediaArticle). These types can be tested in the <if> syntax.

However CSL reserves some types as generic fallbacks. Thus, for example, a film will use the rule which has been defined for book in the absence of any rules specific to its type.

You must test a specific type before its generic fallback. For instance, as “book” is the fallback for “film”, you need to test for “film” before testing for “book” if you want it to work correctly.