This project is read-only.

Sorting different source types alphabetically and by reference order

Sep 24, 2012 at 7:12 PM

Hi folks,

First, thank you so much for developing this tool. it's been extremely helpful and exciting.   

 I don't know XML well, but I know some rudiments of coding, so i've been able to edit the Harvard Anglia style to do a number of things to match my company's referencing style using BibExtender.  Aside from simple formatting thing, the main thing I've been able to change is to get the bibliography to sort first alphabetically, and then by the year suffix. To do this, I changed the sortkey element to this:

<sortkey>{%Author:2|InternetSiteTitle|"Anon."%.}{ %Year|"n.d."%{%YearSuffix%}</sortkey>

This also has another intended effect, which is that the first in-text citation's suffix is "a" and then goes in order from there. Before, it would have been strictly alphabetical, so the first citation may have been (Source, 2012e), instead of (Source, 2012a).  

So, this is all working perfectly well for me, except for one thing: if I have more than "source type" by the same author and year, they do not sort with each other.  For example, I'll have a slew of "DocumentFromInternetSite" sources that are sorted appropriately with suffixes a-c, and then it will restart the letter suffix lettering with a different source type e.g. "Report".  Basically it would like this:

Author, 2012a. title. Website link.

Author, 2012b. title. Website link.

Author, 2012c. title. Website link.

Author, 2012a. title. [NO LINK TO WEB BECAUSE IT IS A REPORT]

I’ve uploaded my version of the XML file here in case that is helpful:


Sep 25, 2012 at 2:49 PM

Can't you adapt your sortkey to incorporate the source type? So everything is first sorted by author, then by type, and finally by year. So

<sortkey>{%Author:2|InternetSiteTitle|"Anon."%.}{ %Year|"n.d."%{%YearSuffix%}}</sortkey>

would become something like

<sortkey>{%Author:2|InternetSiteTitle|"Anon."%.}{ %SourceType%}{ %Year|"n.d."%{%YearSuffix%}}</sortkey>

NOTE: you are missing a matching closing bracket in your sortkeys! There should be another } after the YearSuffix element.

I'm not sure why you include the year suffix in the sort key, the sort key is actually part of what will decide on what the suffix will be. But if it works, leave it :-)

Sep 25, 2012 at 4:01 PM

Hi Yves,

Thanks for your help.  I tried two things: 1) replaced the missing bracket and re-ran that way, and also tried the new code you provided, but no luck.  I can't give you a really good reason WHY i used suffix code in the sort, other than I thought it might work, and it almost did, but the fact that it won't effectively ignore source type when applying suffixes is keeping it from being useful.  

Have any other ideas for how I could make that work?



Sep 25, 2012 at 9:12 PM

I'm confused. Do you want the suffices to restart per type or not?

Do you want

Author, 2012a. title. Website link.
Author, 2012b. title. Website link.
Author, 2012c. title. Website link.
Author, 2012a. title. [NO LINK TO WEB BECAUSE IT IS A REPORT]

or do you want

Author, 2012a. title. Website link.
Author, 2012b. title. Website link.
Author, 2012c. title. Website link.
Author, 2012d. title. [NO LINK TO WEB BECAUSE IT IS A REPORT]

What exactly are you sorting criteria and their order?

1. Author
2. Year
3. SourceType?
4. Title?

Sep 25, 2012 at 9:20 PM

I'm sorry for not being clear. I do NOT want the suffices to restart.  The second list is what I would prefer.  Basically, I want sourcetype to be ignored. Bibliography should be sorted first by author, then by year, then by reference order. The suffixes should also be determined by reference order. In other words, the first reference in the doc by the same author-year would appear as (Author, 2012a), whereas the 5th reference in the doc  by the same author-year would be (Author, 2012e), regardless of the source type. 

Sep 26, 2012 at 2:55 PM

I took a better look at your style.

For starters, you are using an old version of BibWord (2.5). The current version is 2.8 and contains several fixes and extra features. Upgrading is straightforward, just download the latest style template and replace the data element (<xsl:variable name="data">...</xsl:variable>) with yours. Styles are backwards compatible.

Next stop sorting. You are using the same sortkey everywhere. That makes no sense. For example, a book has no InternetSiteTitle so that field will always be empty. Why would you include it in your sortkey? The same for using the author field in a movie. You would either sort on title or on producer.

There is a limitation in using the reference order in your sorting keys. The problem is that sorting keys are seen as strings, so if you would have 'author, year, order' and the following two entries 'author1, 2012, 5' and 'author1, 2012, 12', the second one would come for the first one as 1 is lower than 5. So I extended the template with an extra function to format the reference order:

<!-- Formats a reference order number. -->
<xsl:template name="format-reforder">
  <!-- A reforder to format. -->
  <xsl:param name="reforder" />
  <!-- Options for reforder formatting. -->
  <xsl:param name="options" />
    <xsl:when test="contains($options, 'l')">
      <xsl:value-of select="substring(concat('00000', $reforder), string-length($reforder) + 1, 5)"/>
      <xsl:value-of select="$reforder"/>

Basically, if you provide an l switch the number will be formatted as a 5 digit number with leading zeroes.

You have to be careful with sorting if your citations don't display authors in the same way as your bibliography. In your style only the first author is shown if there are more than two. So if you had two entries by "A, B, C" and "A, D, E", they would both end up in your in-text citation as "A et al.".

I went over some of your sortkeys and changed them a liitle:

ArticleInAPeriodical: {%Author:2|Title|"Anon."%}{ %Year|"n.d."%}{ %RefOrder:l%}
Book: {%Author:2|Title|"Anon."%.}{ %Year|"n.d."%}{ %RefOrder:l%}
BookSection: {%Author:2|Editor:2|Title|"Anon."%.}{ %Year|"n.d."%}{ %RefOrder:l%}
ConferenceProceedings: {%Author:2|Title|"Anon."%.}{ %Year|"n.d."%}{ %RefOrder:l%}
DocumentFromInternetSite: {%Author:2|InternetSiteTitle|"Anon."%.}{ %Year|"n.d."%}{ %RefOrder:l%}
Film: {%Title|"Anon."%.}{ %Year|"n.d."%}{ %RefOrder:l%}
InternetSite: {%Author:2|Title|"Anon."%.}{ %Year|"n.d."%}{ %RefOrder:l%}
Journal Article: {%Author:2|Title|"Anon."%.}{ %Year|"n.d."%}{ %RefOrder:l%}
Report: {%Author:2|Title|"Anon."%.}{ %Year|"n.d."%}{ %RefOrder:l%}

Finally, the suffices. Nothing to change here. Suffices are needed when you have two entries which would look the same as in-text citations if you didn't have them. So basically, the decision is made using the same format string as the one for the citation with the exclusion of the YearSuffix element. After all, this is the element you try to calculate.

I uploaded the adapted style and some sample files to

Sep 26, 2012 at 9:37 PM

You've gone above and beyond. I have not tried this yet, but I'm amazed and thankful for your efforts and your patience with my Noobs. I haven't tried this out yet, but will do so soon.  I'll let you know how it goes.


Jan 21, 2013 at 3:53 PM

Hi ,

I have the same problem with sorting a,b,c in my text.  I tried to download the style mentioned in the last link but it doesn't work. Can one of you please upload it again?

Thanks, Zahra

Jan 27, 2013 at 11:44 AM

The original poster was creating his own style based on Harvard Anglia. So I very much doubt you have the same problem. What style are you using and what exactly is your problem?