Table of Contents

CSL Syntax Summary

This page is intended to be a brief description of some of the constructs that can be used when creating CSL definitions.

It also shows how they interact with zotero where appropriate.

Preamble

At the beginning of the XML markup is the usual header information. This will look something like this

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

This can be copied more or less verbatim, the class is the only part you may want to change. Note that the namespace declaration on the root element binds the elements in the style to that namespace URI. The class can either be note or in-text. Use note for citation styles that use numbered citations, and in-text for those that have author-date like types.

Info

The next section contains information about the edition of the markup definition. The content model for the CSL metadata is borrowed from Atom. The idea behind this is to include sufficient information that CSL styles can be hosted in distributed style repositories, that users may be able to subscribe to collections of styles in their fields of interest, and that the style files can be updated transparently as needed.

As with Atom, the cs:id element is required, and must be a valid, stable, and unique URI. Make sure you choose the ID carefully, as tools will use this to assess the identity of the style. If you cannot give it a good, stable, unique URI that is HTTP resolvable, you can instead use some like a GUID in URN form.

Likewise, tools will also use the date-time value of the cs:updated element to assess whether the style has changed since last accessed or cached.

<info>
 <title>A new format</title>
 <id>http://www.zotero.org/namespaces/CSL/newformat</id>
 <author>
  <name>My name</name>
  <email>my-address@wherever.com</email>
 </author>
 <updated>2007-10-12 03:33:00+05:00</updated>
 <summary>My great new style format.</summary>
</info>

This can also include various other attributes, including contributor and a number of other fields which may be useful. The cs:category element can be particularly useful for browsing large repositories and for allowing users to subscribe to styles within particular content areas. For this reason, be sure to include them to ensure the infrastructure of CSL styles scales gracefully.

Macros

The next section is typically a list of macro definitions. 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:

Citation

Now we get to the first of the key parts. The citation construct is the part that appears in-line in the text. This may just be a simple number in some styles, or an (author, date) type of citation.

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

The options allow you to control various things about the citation, which will be considered later. The layout is where the actual information is formatted for putting on the page. The layout directive itself has some optional parameters, the most common being to use prefix and suffix and delimiter. For instance

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

is common for the author/date format layout.

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.

Options

There are numerous options available. Most apply to both citations and the bibliography, although there are a few that are specific. Here is a summary of them with an example of each.

Common options

These apply to both bibliography and citation 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"/>

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 are formatting parameters and apply to many of the markup directives.

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 dependant on the item. An example is the label for pages, which can be p. or pp. depending on if its a single page. For instance

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

locator is the other variable commonly used. The usual formatting, short/long forms and an option to include a trailing ‘.’. Labels can also be applied without a variable inside a &lt;names&gt; 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">