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.
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:
info
: contains metadata describing the style (name of the style, authors of the style, etc)citation
: describes how in-text citations should be formattedbibliography
: describes how bibliographies should be formattedmacro
: allows for reuse of formatting instructions, allowing for more compact stylesterms
: allows for the modification of locale-specific strings (e.g. “edited by” can be changed in “ed. by”)
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.
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:
xmlns
: the namespace declaration that binds the elements in the style to the given namespace URIclass
: with two possible values, “in-text” or “note”, this specifies whether the style is note-based or uses in-text citations coupled to a bibliographyxml:lang
(optional): specifies the locale used for argument values within the styledefault-locale
(optional): sets the localization of the style output. The effect is currently limited to localization of preset strings (e.g. “edited by”), but plans exist to extend this to punctuation (French quotes, different punctuation around quotation marks in American and British English). N.B. Support for the default-locale argument has not yet been implemented in Zotero. Currently styles are solely localized according to the locale set in Firefox, which can be overruled with the export.bibliographyLocale user preference.
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">
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:
id
: this required field should preferably be a valid, stable, and unique URL if the style is to be made publicly available. Make sure you choose the id carefully, as it will be used to identify the style (if a style is installed in Zotero, it will overwrite an already present style with the same id). For styles uploaded to the Zotero Style Repository this can be the link to your schema (e.g. http://www.zotero.org/styles/your-style-filename).title
: name of the style (required). The title is shown in the Zotero Style Repository.author
/contributor
/translator
(): people who write a new style, or make significant changes can claim authorship (see example above). For smaller changes the contributor role can be used. In both cases one should supply a name. An email-address and URI are optional.updated
: the contents of this required element is used to assess whether the style has changed since the last time it has been accessed or cached. If uploading to the Zotero Style Repository, the timestamp will be generated automatically. The syntax of the timestamp is described here.published
: similar to updated, this element contains a timestamp, in this case the timepoint when the style was initially created or first made available.category
: styles can be divided in a number of categories. This information can be used to ease browsing of large style repositories and could allow users to subscribe to styles within particular content areas. The different types of categories are:author-date
: e.g. “… (Doe, 1999)”numeric
: e.g. “… [1]”label
: “ … [doe99].”note
: the citation appears as a footnote or endnotein-text
: the full citation appears in-linegeneric-base
category is meant for generic styles like Harvard and APA): anthropology
, astronomy
, biology
, botany
, chemistry
, communications
, engineering
, generic-base
, geography
, geology
, history
, humanities
, law
, literature
, math
, medicine
, philosophy
, physics
, psychology
, sociology
, science
, political_science
, social_science
, theology
, zoology
rights
: a license dictating how the style file may be modified and distributed by others. See, e.g. http://creativecommons.org/license/issn
: a style written for a specific journal can include the journal's ISSN (International Standard Serial Number). N.B. currently Zotero only supports a single ISSN. There are plans to add a issnl
element to allow for inclusion of the ISSN-L, and also to allow for multiple ISSNs (as many journals have both a print and online ISSN).
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)”).
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.
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:
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.
Most of following syntax applies to the macro
, citation
and bibliography
sections.
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.
These apply to both citation
and bibliography
sections.
<option name="et-al-min" value="6"/>
<option name="et-al-use-first" value="6"/>
<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"/>
<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"/>
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.
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.
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.
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.
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.
The following formatting parameters for most elements specifying output.
prefix
: text to insert before the main outputsuffix
: text to insert after the main outputfont-family
: which font family to use.font-style
: normal
, italic
or oblique
(slanted).font-variant
: normal
or small-caps
.font-weight
: normal
, bold
or light
.text-decoration
: none
or underline
.text-case
(modifies the capitalization of the text): lowercase
, uppercase
, capitalize-first
, capitalize-all
, title
, sentence
.vertical-align
: baseline
, sup
or sub
.display
: if set to block
makes this a block of separate text.quotes
: true/false to include quotes around it.For instance
<text variable="edition" prefix=" " suffix=" ed. "/> <text term="retrieved" text-transform="capitalize" suffix=" "/>
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”)
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=". ">
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
position
which can be tested against first
, subsequent
, ibid
, ibid-with-locator
. The first time a citation is made to a certain item, the position will be first
. If the next citation again references that item, the position becomes ibid
, or, if a locator is added in the Insert Citation window, ibid-with-locator
. Finally, if the same item is again referenced after some other items have been cited, the position becomes subsequent
.disambiguate
which can be tested against true/false. This allows two citations to see if they are the same still.locator
which can be compared against locator types such as page
, chapter
, verse
etc.match
- this allows and/or/not like behaviour by setting against all
/any
/none
. This is required if you test multiple types or variables too.Multiple variables can be tested as in
<if type="chapter book" match="any">
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.