Translations of this page:

We’re in the process of updating the documentation for Zotero 5.0. Some documentation may be outdated in the meantime. Thanks for your understanding.

修改 CSL 样式

虽然没有 CSL 的编辑器,但是修改样式其实一点都不困难。你甚至都不需要太多的 XML 知识,只需要按照下列步骤进行即可。

打开测试面板

在Firefox浏览器地址栏中输入

chrome://zotero/content/tools/csledit.xul

如下所示。

打开Zotero面板,选定一个或多个条目,关闭Zotero面板,在测试面板右侧下拉菜单中选择一个样式,CSL样式将会在第一个文本框中出现,引文和参考文献目录将在第二个文本框中出现。

动它一下

现在你可以在第一个文本框中改动XML文件的内容。只要改动后的文件仍然具有正确的结构,改动后的格式就会在第二个文本框中显示。 注意你所做的改动不会自动保存,请自行保存。你可以将相应的文本复制到文本编辑器中,存为以csl文件(*.csl)。

示例

在CSL文件的末尾,会有<citation><bibliography> 这两块代码,前者决定引文的格式,后者决定参考文献的格式。 一般情况下,你只需要改动这两个部分。

code代码块决定引文格式

  <citation>
    <option name="collapse" value="citation-number"/>
    <sort>
      <key variable="citation-number"/>
    </sort>
    <layout prefix="(" suffix=")" delimiter="; ">
      <text variable="citation-number"/>
    </layout>
  </citation>

bibliography代码块决定参考文献格式

<bibliography>
    <option name="second-field-align" value="true"/>
    <layout>
      <text variable="citation-number" suffix=". "/>
      <text macro="author"/>
      <text macro="title" suffix=". "/>
      <choose>
	<if type="book">
	  <text macro="edition" prefix=" " suffix=" "/>
	  <text macro="publisher" prefix=" " suffix="."/>
	</if>
	<else-if type="chapter">
	  <group prefix=" " suffix=". ">
	    <text term="in" suffix=": " text-case="capitalize-first"/>
	    <text macro="editor"/>
	    <text variable="container-title"/>
	  </group>
	  <text macro="publisher" prefix=" "/>
	  <text variable="page" prefix=" p. " suffix="."/>
	</else-if>
	<else>
	  <text variable="container-title" suffix=" " form="short"/>
	  <text macro="date" suffix=";"/>
	  <text variable="volume"/>
	  <text variable="issue" prefix="(" suffix=")"/>
	  <text variable="page" prefix=":" suffix="."/>
	</else>
      </choose>

          </layout>  
</bibliography>

改变标点符号

引文格式的差异通常会很小,你可以找一个类似的格式,只需要做些许改动,就可以得到你想要的格式。 一般情况下,你只需要改动参考文献目录中的标点符号,各个项目(作者,题目,年份等)的位置就可以了。

在 Zotero 中,分别以prefix, suffix 和 (group) delimiter属性来标识。

例如,下列改动将会将卷号由格式(9)变动为[9]

<text variable="issue" prefix="(" suffix=")"/>
<text variable="issue" prefix="[" suffix="]"/>

改变参数

当一篇引文的作者有多个的时候,常常需要显示 et al. 的缩写,这需要一个option参数。这个设置在CSL 0.8.1 和 1.0 中有所不同。

CSL 0.8.1

For example, to remove all given-name disambiguation, find the line:

<option name=“disambiguate-add-givenname” value=“true”/>

And just delete the whole line. You'll see the change occur immediately in the preview pane below.

如果有4个以上作者时,只显示第一个作者,并加上 et al. ,那么会有如下代码:

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

不妨将4改为6,将1改为3,你会在下面的文本框中看到改动后的结果。

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

The CSL 0.8.1 Syntax explains how CSL 0.8.1 works. Common options you might wish to change are here.

CSL 1.0

In CSL 1.0, the same options - and several new ones - exist, but they are not listed separately, but included in the <citation> and <bibliography> lines, e.g.

<citation et-al-min="4" et-al-use-first="1" disambiguate-add-year-suffix="true" disambiguate-add-names="true">

A bit of trial and error, and testing with a few combinations should help. You can see what different items and combinations will look like by selecting them in Zotero (Ctrl-click to select multiple items), and then “Refresh” at the top-left of the Test pane.

TIP : If your style has a mistake, an error message is displayed instead of a citation. Often these messages can help you figure out what you're doing wrong.
Also, you can use Ctrl-Z to undo, or if you get really stuck, just select the style from the drop-down again and you're back where you started.

改变样式的标题(Title)和 ID

强烈建议你修改样式的Title和ID。

否则:

  • 你安装新的样式会覆盖掉原有的样式
  • 自动更新之后,你的自定义样式又会被更新覆盖。

这部分内容在文件的开头,像这个样子:

<title>Harvard Reference format 1 (Author-Date)</title> 
<id>http://www.zotero.org/styles/harvard1</id>

你可以将其改为

<title>Harvard Style Modified</title>
<id>http://www.zotero.org/styles/harvard-modified</id>

Different CSL versions

Starting with version 2.1, Zotero uses an updated version of the Citation Style Language, CSL 1.0, which has a changed syntax. The styles that come with your copy of Zotero as well as most styles in the Zotero Style Repository are in the old CSL 0.8.1 format and are updated internally. You can still edit CSL 0.8.1 styles, but if you want to make more substantive changes or take advantage of one of the new features of CSL 1.0, you should download an updated version of the style from the CSL 1.0 repository or use update the CSL 0.8.1 style yourself. You cannot mix CSL 0.8.1 and 1.0. If you want to use some of the new features in 1.0 you will need to use a style converted to 1.0.

使用你自定义的样式

你需要将一个样式安装到 Firefox 中,或者说安装到 Zotero 中。

将样式的文本全选,复制并粘贴到文本编辑器中,保存为一个以.csl结尾的文件。然后,拖动该文件到 Firefox 窗口上面,会提示你是否安装,如下图所示。

选择确定。该样式就会安装到你的 Zotero 中了。

Some Slightly more advanced tips

For anything more advanced, this page is your friend. It also includes links to comprehensive documentation for both CSL 1.0 and CSL 0.8.1.

If you are making several changes, you might want to copy all the CSL code from the top window (Ctrl-A, Ctrl-C) and paste it into a new file in a text editor. Notepad works fine, though using a good text editor designed for programming like the free Notepad++ for Windows or TextWrangler for Mac OS X, can help you to see the structure clearly and not make mistakes. Set the “language” to XML (CSL is based around XML).

You'll find that your fellow users on the Zotero forum will be happy to help you with any problems. The forums also have little nuggets of gold all through them, and searching usually finds the solution to any issue. If you are still having trouble, post a question in the Styles section of the forums and it's likely to get answered quickly.

Sharing Styles

If your new style has general appeal, consider submitting it for inclusion into the Zotero Style Repository.

zh/dev/citation_styles/style_editing_step-by-step.txt · Last modified: 2017/11/12 19:53 (external edit)