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.
<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.
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.
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.
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?
It just wasn't clear to me if it was supposed to have an effect (on sorting).
"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).
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.
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.
http://citationstyles.org/downloads/specification.html#name-part-order (search for "sorting order")
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.