Sort by last name

May 24, 2008 at 4:08 PM
Is it possible to add automatically sorting by last name and not by citations appearance in the document ?
May 25, 2008 at 10:35 PM
Edited May 25, 2008 at 10:53 PM

karatist wrote:
Is it possible to add automatically sorting by last name and not by citations appearance in the document ?

I do not really understand how you would cite your sources using numbers and then create a bibliography which has a different order than your numbers.

A bibliography is currently sorted using the following line in the for-each loop:

  xsl:sort select="b:RefOrder" data-type="number"

So you could adjust this line for your needs. As a start, something like the following line could work:

  xsl:sort select="b:Author/b:Auhtor/b:Person[1]/b:Last" data-type="text"

However, each item in a bibliography has a reference number while not every entry might have an 'person author'. The author might be a corporation, an editor or might even be missing. So when you want to sort on anything other than reference order, you will need to define exactly how the sorting should be done.

I am currently working on a stylesheet for the Harvard reference model. There the sorting has to be done in the way you request. It will probably take a few weeks before I will release something. Mainly because I can not figure out the correct formatting for Harvard style (each publication authority seems to have its own reference to it). I already solved the sorting problem as follows: before entering the for-each loop of the bibliography, I extend each source with an extra field (b:ExtSortKey) which is filled with a string which is a combination of author or editor last names, title, and year of publication. Then the sorting for the for-each loop becomes:

  xsl:sort select="b:ExtSortKey" data-type="text"

If you want the full example, I can probably put a beta version of the style sheet up by the beginning of June.

May 27, 2008 at 2:47 PM
Edited May 28, 2008 at 8:55 AM

I added an advanced stylesheet template to the project. Among things, it contains the extension functionality I talked about in my previous post. It also contains an example on how to use it to sort bibliography entries based on year and title.

Hopefully this can help you with what you want to accomplish.

edit for spelling mistake (short => sort)

May 28, 2008 at 6:44 AM

Thank you for your reply, I will be happy to get a beta version. Regarding the sorting - this is exactly what LaTeX is doing, and this is what I need for my thesis. The bibliography list should be sorted by last name AND only then the numbers should be given to all items of the list. This way it will be sorted both by numbers and by last name.

You are doing a great job, thank you.
May 31, 2008 at 1:50 PM
Edited May 31, 2008 at 4:46 PM

I went over the bst stylesheet you send me and now have a clear grasp of what you want to achieve.

Unfortunately, what you require is not automatically possible using Word 2007 as far as I can tell. Sorting the elements in the bibliography is easy. The problem is the numbering of in-text citations afterwards. In Word 2007, in-text citations are independant from bibliographies. So it is not possible to communicate the position of an entry in the bibliography, to a b:Citation element. Hence, it is impossible for a bibliography to tell which value should be placed between brackets in a in-text citation. Also, a b:Citation element contains only one b:Source element. So sorting all b:Source elements to calculate a number every time you wish to display an in-text citation is not possible either (let alone the computational complexity of this solution). Finally, the b:RefOrder element indicates the order of the appearance of b:Source elements in the text and not in the bibliography. So that value can not be used either.

Indirectly Microsoft admits to know about the issue with the following quote:
  "If you choose a GOST or ISO 690 style for your sources and a citation is not unique, append an alphabetic character to the year. For example, a citation would appear as [Pasteur, 1848a]."

So they admit it is not possible to access the other sources within a b:Citation element. What is even more strange, if you are able to add the "a" to the year in the in-text citation, you should also be able to add it to the year in the bibliography. Something which is not possible.

At the moment I can see one solution which requires you to do a lot of work when you finished your document:

  • create your text with in-text citations
  • generate your bibliography in the format you want
  • use the numbers from the generated bibliography and add them as suffixes of citations while surpressing all other info (\s <number> \n \t \y) 

Like I said, a lot of postprocessing work since you have to handle every entry separately, but it should do the trick.

Jun 7, 2008 at 6:50 PM

Unfortunately, I didn't succeed to do the trick.

I have several questions:

  1. How can I generate my bibliography in the format I want ? (Tell me if I understand right - I changed the sorting order in XLS file to select="b:Author").
  2. When I add at least one citation, "RefOrder" of all bibliography is automatically changed (the cited one became the first one). I added to the citation field "\s 5", for example, but this did not help.

Can you please elaborate on what did you mean ?

Thank you.

Jun 8, 2008 at 10:02 PM
Edited Jun 9, 2008 at 5:43 PM
Regarding your first point:
Like I posted before, you cannot just simply sort on an element. There is no guarantee that the element will be available or contain data. In the Advanced Stylesheet Template I have put up an illustration on sorting based on a key. You will have to define the key yourself for your case though.

Simply sorting on the 'text' version of a b:Source/b:Author element is pointless since there no guarantee that the 'real' authors are listed as a first element. For all you know, it could be of the format: 

which would imply that this source would be sorted based on translator rather than author. Even a 'text' version of b:Source/b:Author/b:Author can not be used as a sorting key since some books have no authors but just editors, while patents have inventors rather than authors. So as you can see, obtaining a value for your sorting key should be done rather carefully.

You can try your b:Author and hope for the best, but if everything turns out fine, it's just a lucky shot. Also, on that line you have to switch the data-type from "number" to "text". And you can no longer use RefOrder in the first column of the table since those are now unordered if you sort on the authors.

Regarding your second point:
In the IEEE.xsl stylesheet, there is no support for \s (or \f for that matter). I did not add any, because there is no requirement for it in the IEEE style. You can easily add support for it yourself though. For the IEEE stylesheet, you would have to replace:
        <xsl:value-of select="/b:Citation/b:Source/b:RefOrder"/>
        <xsl:if test="/b:Citation/b:PagePrefix">
xsl:value-of select="/b:Citation/b:PagePrefix" disable-output-escaping="yes"/>
        <xsl:value-of select="/b:Citation/b:Source/b:RefOrder"/>
        <xsl:if test="/b:Citation/b:PageSuffix">
xsl:value-of select="/b:Citation/b:PageSuffix" disable-output-escaping="yes"/>
in the citation formatting.

Alternatively, when you finished writing your text and generated your bibliography, you can convert it to static text and then manually edit/replace every in-text citation with the value you want. That at least gets your bibliography formatted correctly. For that matter, I would display something else than b:RefOrder as intermediate value for the in-text citations. Something which will allow you to map it more easily to entries in the bibliography (tag, first author, title, ...)

(edit error in code)
Jul 2, 2008 at 10:32 PM
I have done my own style, and everything looks just as I want it to. Just one thing left. The pagenumbers. How can I print the page numbers that are induvidual for each reference. Thus, I dont want to print out the page numbers that can be set in the source manager. Does anyone know what this paremeter is named or know another way to print the numbers? I know I can type them in manually, but anyway, would be nice to solve it.

Thank you in advance!
Jul 4, 2008 at 8:24 PM
The page numbers of a source are stored in /b:Citation/b:Source/b:Pages.

The page numbers entered with the \p switch of the citation field (or by right-clicking an in-text citation and picking "Edit Citation" instead of "Edit Source") are stored in /b:Citation/b:Pages.

Jul 17, 2008 at 10:40 PM

karatist wrote:

... The bibliography list should be sorted by last name AND only then the numbers should be given to all items of the list. This way it will be sorted both by numbers and by last name.

There is solution, but unfortunately it doesn´t use bibliography functionality so it's on you to watch correct citation style. You can use combination of numbered list and cross reference. Just create list of sources with any kind of numbering:
  1. abc
  2. bcd
  3. ...

Then you can create cross reference to number of paragraph from list (e.g. it shows 1 for item 'abc'). When you add new item to the end of the list, simply sort the list by paragraph:

  1. aaa
  2. abc
  3. bcd
  4. ...

Because every item has it's own reference number which is independent on rank in the list your cross reference can point to this new place but it also can take new ordered number of paragraph. Cross reference will be changed after updating of fields or re-opening of document (e.g. 1 will be changed to 2 for item 'abc').