Sort bibliography by author - priority of surnames, given names, and initials

I have created 3 different macros that I hoped would be able to achieve 3 different results for bibliography sorting:

<macro name="bib-sort-1">
<names variable="author">
<name name-as-sort-order="all"/>
</names>
</macro>

With bib-sort-1, I expected the bibliography to be sorted according to the following order: [surname 1, given names 1, surname 2,...etc] (where the number refers to author number)

<macro name="bib-sort-2">
<names variable="author">
<name name-as-sort-order="all" initialize-with=""/>
</names>
</macro>

With bib-sort-2, I expected the bibliography to be sorted according to the following order: [surname 1,initials 1, surname 2,...etc] (i.e. full form of given names don't matter - instead only their initials matter)

<macro name="bib-sort-3">
<names variable="author">
<name name-as-sort-order="all" form="short"/>
</names>
</macro>

With bib-sort-3, I expected the bibliography to be sorted according to the following order:
[surname 1, surname 2, surname 3,....etc]

To use the macros, I put the desired one in the sort section of the bibliography (e.g.):

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

However, my bibliography sort order is not being affected by changing the macro used in the sort key. In all cases the bibliography is being sorted in the way I expected for bib-sort-1.

Are my expectations wrong?
If yes, are my alternative desired sort orders possible in CSL?
I am a novice at this, but I have read the CSL spec guide. However, I don't find the section on sorting as clear as the rest of the guide.
  • Which version of Zotero are you testing with? If you haven't already, please try with Zotero 2.1.7 (just out a couple of days ago), and let us know how you fare with that version.

    If you still have problems, please paste the style and a Zotero RDF export of sample data (separately) to gist.github.com, saving each as a public gist, and posting the URL from the address bar for each back to this thread.
  • I was already using Zotero 2.1.7

    Here is the CSL file containing the 3 macros: https://gist.github.com/1010017
    Here is an RDF export to test for author name sorting https://gist.github.com/1010024

    With bib-sort-1 I expect the order to be:
    Doe, Jane B. & Doe, John A. (2009)
    Doe, John A. & Bloggs, Joe A. (2011)
    Doe, John A. & Smith, John A. (2010)

    With bib-sort-2 I expect the order to be:
    Doe, John A. & Bloggs, Joe A. (2011)
    Doe, John A. & Smith, John A. (2010)
    Doe, Jane B. & Doe, John A. (2009)

    With bib-sort-3 I expect the order to be:
    Doe, John A. & Bloggs, Joe A. (2011)
    Doe, Jane B. & Doe, John A. (2009)
    Doe, John A. & Smith, John A. (2010)

    However I get the same order regardless of which macro I use.
  • Thanks, test data is what I needed. I'll take a look soon and get back.
  • Sorting by anything less that the full name was indeed broken. A processor version containing the fix will be released soon (probably tomorrow morning), after which the update will make its way into Zotero.
  • edited June 6, 2011
    Thanks, I look forward to the fix.

    To help my understanding:
    Were my expectations for the 3 macros correct?
    Does name-as-sort-order have any influence on sorting or is it only for rendering?
  • I'm pretty sure that name-as-sort-order does not have any influence on sorting (thus the name of the term). I don't think sorting by first name is possible. But I also don't think it's ever required.
  • edited June 6, 2011
    No, I don't think its ever required either.
    It just wasn't clear to me if it was supposed to have an effect (on sorting).
  • edited June 6, 2011
    According to the CSL specification, name sorting should always happen with name-as-sort-order set to "all". This is discussed at http://citationstyles.org/downloads/specification.html#sorting-variables .
  • but that part of the specs at least isn't clear about what happens with macros that include name variables. I'm pretty sure that's the same, though, right?
  • http://citationstyles.org/downloads/specification.html#sorting-macros: "For name sorting, the name-as-sort-order attribute on cs:name elements is set to "all"."
  • Thanks.

    "For name sorting, the name-as-sort-order attribute on cs:name elements is set to "all"."

    Just some feedback from my perspective: It wasn't entirely clear to me when I previously read the guide if that sentence was referring to a deafult setting or (as I now understand it) an overriding setting. Maybe being more explicit would avoid confusion. Although I suppose this only became a source of confusion for me because I wasn't able to trust my own test of whether changing its setting affected sort order (due to the apparent broken sorting).
  • edited June 6, 2011
    I've recently rewritten most of the specification in an effort to improve clarity. The new (proposed) text for name sorting using macros is: "As for names sorted via the "variable" attribute, names sorted via "macro" are returned with the cs:name attribute name-as-sort-order set to "all"."
  • omian,

    Thank for your care in preparing the test data and style. Having complete samples greatly simplifies things at this end.

    Sorting by initialized and short-form names has now been fixed in a fresh citeproc-js release (1.0.179). You can watch for the new release on the Zotero development timeline. After it has been adopted in the trunk and merged to the 2.1 branch, you will be able to test the repaired behavior by (backing up your documents and data, and then) installing the branch XPI.

    If you do install the branch XPI for testing, be sure to manually install the next stable version of Zotero (2.1.8) when it comes out, to avoid receiving possibly-unstable updates from the branch.
  • Does name-as-sort-order have any influence on sorting or is it only for rendering?
    As Rintze and adamsmith say, this option is turned on automatically inside a sort key. The idea behind the design (stated clearly in the CSL specification -- I just messed up the implementation) is that you should be able to dual-purpose a macro for visual rendering and as a sort key, without making any special adjustments.
    Were my expectations for the 3 macros correct?
    Yes, perfect.
  • edited June 6, 2011
    So to answer the question most directly:
    Does name-as-sort-order have any influence on sorting or is it only for rendering?
    No, it is only for display ("rendering").

    Sorting logic is effectively hard-coded.

    FWIW, when I've coded this stuff, I've tended to have internal representations for sorting like:

    doe:jane;mao:zedong

    For the spec revisions, it might be worth including the original inspiration behind the design: how to sort and display an item with an author list with a Western name (sort-as-display=false; sort="Doe, Jane", display="Jane Doe") and an Asian name (sort-as-display=true; sort and display="Mao Zedong").

    If I hadn't gone this way, contributor macros would either be not very international-friendly, or quite a bit more complex.
  • We already have that in the spec, no?

    http://citationstyles.org/downloads/specification.html#name-part-order (search for "sorting order")
  • Yeah; I'd just been looking in the sorting section.
  • edited June 7, 2011
    Thanks for the further clarification. I think it would have been more clear to me if the sentence was "For name sorting, the name-as-sort-order attribute on cs:name elements is [always] set to "all", [overriding its setting in the macro]".

    I have just re-read the whole sorting section and realised that the preamble to the sorting variables and sorting macro section is helpful:

    "The values returned for variables and macros called in cs:sort may differ from the "ordinary" rendered values. These differences are detailed below."

    Unfortunately, this does'nt get read when arriving at sorting variables and sorting macros via the TOC links. I know to is alluded to again at the start of each section, but not quite as explicitly (to the novice at least).

    Another bit of feedback is that when reading the document I did find the extensive use of links helpful, but as a result also found it quite easy to get lost in the overall structure of the document (and consequently, how things were relevant within the overall scheme of CSL). A static TOC tree the left hand side (highlighting your current location), independent of the main pain, may have been helpful.
  • Thanks for the feedback. I'm not sure how to implement a floating TOC. You could try to open links in a new tab though, so you don't get lost in your original tab.
Sign In or Register to comment.