Sorting by editor substituting authors

edited February 7, 2017
Hi everyone,
I'm currently finishing the style for my institute. So far, I'm pretty happy, but I can't get the sorting to work. I wish to sort the bibliography alphabetically by authors, which should be substituted by editors if no authors are available. However, currently, those publications are placed at the bottom.

Current behaviour:

A-Surname, Name…
C-Surname, Name…
B-Surname, Name (ed.)…

Should be:
A-Surname, Name…
B-Surname, Name (ed.)…
C-Surname, Name…


I can't get it to work and have no idea why. Relevant code:

<sort>
<key macro="sort-key"/>
</sort>

<macro name="sort-key">
<text macro="contributors-long" suffix=" "/>
<text macro="issued"/>
<text macro="title-long" suffix=" "/>
</macro>

<macro name="contributors-long">
<choose>
<if variable="author">
<names variable="author" font-variant="normal">
<name font-variant="normal" and="text" delimiter-precedes-last="never" name-as-sort-order="all">
<name-part name="family" font-variant="normal"/>
</name>
<et-al term="et-al"/>
</names>
</if>
<else>
<choose>
<if type="bill book graphic legal_case motion_picture report song" match="any">
<names variable="editor">
<name name-as-sort-order="all" and="text" sort-separator=", " delimiter=", " delimiter-precedes-last="never">
<name-part name="family" font-variant="normal"/>
</name>
<et-al term="et-al"/>
<label form="short" prefix=" (" suffix=")"/>
</names>
</if>
</choose>
</else>
</choose>
<date variable="issued" prefix=" (" suffix=")">
<date-part name="year"/>
</date>
</macro>


Any help would be greatly appreciated!
  • Take a look at the style for American Psychological Association (apa.csl) for an example of this. Rather than making a separate sort-key macro, you just want to give several keys say give the variable priorities for sorting.

    Also, your contributors macro probably won't work as intended. Rather than <choose> elements, you want to use use <substitute parameters within the <names> elements.

    You also don't need to specify font-variant="normal", as this is the default, and you only need to use the et-al parameter to change the formatting (to italics, for example). If it is in normal text, the parameter can be omitted.

    The macro as written also doesn't print author/editor first names/initials; is that intended?

    Finally, it's unusual to include the issued date in a contributors macro. What is your thinking there?


    Here is code that should work for you (it includes the issued year):

    The sorting code:
    <sort>
    <key macro="contributors-long"/>
    <key macro="issued"/>
    <key macro="title-long"/>
    </sort>


    The contributors macro, with creator initials
    <macro name="contributors-long">
    <names variable="author">
    <name name-as-sort-order="all" and="text" sort-separator=", " initialize-with=". " delimiter=", " delimiter-precedes-last="never"/>
    <label form="short" prefix=" (" suffix=")"/>
    <substitute>
    <names variable="editor"/>
    <names variable="translator"/> <!-- Including translator is a good idea for items that have neither an author or editor listed -->
    <text macro="title" form="short"/> <!-- You probably want to include the title as a substitute option for items that have no creators -->
    </substitute>
    </names>
    <date variable="issued" prefix=" (" suffix=")">
    <date-part name="year"/>
    </date>
    </macro>


    The contributors macro, without creator initials
    <macro name="contributors-long">
    <names variable="author">
    <name form="short" name-as-sort-order="all" and="text" sort-separator=", " initialize-with=". " delimiter=", " delimiter-precedes-last="never"/>
    <label form="short" prefix=" (" suffix=")"/>
    <substitute>
    <names variable="editor"/>
    <names variable="translator"/> <!-- Including translator is a good idea for items that have neither an author or editor listed -->
    <text macro="title" form="short"/> <!-- You probably want to include the title as a substitute option for items that have no creators -->
    </substitute>
    </names>
    <date variable="issued" prefix=" (" suffix=")">
    <date-part name="year"/>
    </date>
    </macro>
  • Thanks a lot! I have started to customize a downloaded style some time ago, and have always just been tinkering in some areas, that's why it's a complete mess now. Overhauling the hole thing is above my skills, however.

    Seemingly, the date-part was breaking the sorting. After removing it (putting it in it's own macro), sorting is back to usual. I have used your way of substituting, working well. Thanks again.
  • If you need any more help with anything, it's best to post the whole style to a secret gist at gist.github.com and post a link here.
  • Hi,
    I'm back with another question. Trying to add disambiguate-add-year-suffix="true", but not sure where / how. Adding it so cs:citation and cs:bibliography doesn't seem to work.

    Here's the full style, with author and contributors stripped:
    https://gist.github.com/anonymous/a53ea0acb204e0e1be14ea2950d5e20d

    Thanks alot!
  • That works for me to show year suffixes (you only need it at cs:citation FWIW). How are you testing?
  • Testing with example books (duplicate, changed name), footnotes & bibliography, MS Word plugin.
    I'm getting:
    Author (2000): Title. Place: Publisher.
    Author (2000): Different title. Place: Publisher.

    Instead of:
    Author (2000a): Title. Place: Publisher.
    Author (2000b): Different title. Place: Publisher.
  • Could you check in the style editor in Zotero? https://www.zotero.org/support/dev/citation_styles/reference_test_pane it'll be helpful to have the location of the problem narrowed down as closely as possible.
Sign In or Register to comment.