This project is read-only.

Sorting the Bibliography Source & Heading

Feb 4, 2011 at 8:09 PM


First off, thank you for making this great project, I first tried a xsl approach and hated it, bibword makes it a lot easier.

So, I know my questions have been asked before, I used the search, but it's all very mixed-up, specialized answers I found, so I would really appreciate any help.

I've created my own bibword xml following the word document the way I like it, all is great, but:

The sorting and display of the bibliography is not the way I need it yet, I'm so close to finishing but just can't get this right. I'll divide my problem into 3 parts

1: Bibwords sorting seems totally random to me, I can not see the logic. So I tried using the <sortkey> element, but somehow I don't understand it: Since sortkey is added to a source element and not the bibliography element, is it different for every source than? I see no distinction between the sources as is, bibword is freely mixing my internetsites with my books, so why can I give every source a sorting? What I need is to sort by %last (lastname) of the first author when it's books, internetsites by the %title, but  all only alphabetically, and that is it. Can this be done?

2: I must distinguish sources in my bibliography, so I need a literature list, then I need a separate internetsite list. Can this be achived? Even better would be, if I could have a page break between the 2.

3: Finally: If 1 & 2 are done, this would be the icing on the cake: When I insert the bibliography in Word 2010, it automatically adds a heading/title called Bibliography, and makes it a layer 1 title, so it gets the automatic numbering that style has and gets counted when I generate an index. Once I have a separate Internet Site list, this one also needs a title like that (Websites), I assume somewhere you can add html. Knowing where would be very helpful. And is it even possible to assign the title a "word layer/format" from xml, so it gets recognized my automatic indexing?


Thank you for ALL help, I will further explain if i was unclear, just ask.

Feb 5, 2011 at 10:30 AM


Default sorting is based on the reference order of the in-text citations. If you don't display the reference number in front of the sources, then it can indeed seem like the ordering is completely random.

The sortkey is different for every element.  There are not enough common elements between sources of a different type to just create one sortkey that fits all. Suppose you want to sort a journal article, a patent, and a film. The journal article has an author. The patent has no author, but it has an inventor. And the movie has no author and no inventor. But it has a producer which the other two don't have. So you would need 3 keys to be able to sort those 3 types of entries among each other.

You can sort any way you want. For example

  • Books: {%Author:1|Title%} {%Year%} {%Title%}
  • InternetSite: {%InternetSiteTitle|Title%} {%Year%} {%Title%}

For easiness assume the 1 behind author to be the same format you use for displaying authors in your text. {%Author:1|Title%} will ensure that the author will be used and if not available the title. {%InternetSiteTitle|Title%} will ensure that the internet site title is used and if not available the title of the page. So if you would have

The would be ordered:

  • book 1 (sortkey = Doe 2010 A mystery novel)
  • website 2 (sortkey =Glass house 2009)
  • website 1 (sortkey =White House 2008)
  • book 2 (sortkey =Zola 2005 The history)


To do this, you would need to change your ordering. You would have to sort on source type first. You could easily put %SourceType% at the forn of every sorting key. However, this will group all sources by type. So if you would have books, journal articles, patents, and websites, the sources would be grouped accordingly.

If you only wanted to group websites and put all the rest together, that would require some creativity. You would have to use %SourceType:s% and map every source type to a string. By mapping websites to a "z" and all other types to an "a", you would guarantee that only the websites are sorted seperately.

As page breaks are a concept foreign to HTML (with the exception of some printing CSS), I'm not sure you can introduce them.


If all you would need would be 1 title, you should create a simple building block inside Word. There is already for "Bibliography" and "Works Cited" (the latter being a badly chosen title). However, two titles is trickier. This cannot be done by changing a part of the BibWord engine. However, it has been done before ( so it shouldn't be that hard. Noticed that in that thread, I used h4 as heading style. You can use h1, h2, ... They map automatically to the heading styles in your Word document. That should allow them to be incorporated in your TOC by default.

Feb 6, 2011 at 7:31 PM

Thank you very much yves, it took some time, but I think & hope I got it all now.

On 3), I didn't quite understand the passage on building block, in my Word I only see a predefined style for citation, 'bibliography' just gets a normal h1 title style, but this is just want I want anyway.

Anyhow, I followed your other post you linked and I got the XSL working. If it is not one of the 2 sourcetypes I want with a different title (websites and cases) (and logically, those are the 2 types I have given a string=x and string=z for sorting, all the other are string=a, as you suggested under [2]), I just give an empty <h1> back. Is this a 'dirty' code trick or do you think that is ok and won't give me problems?

 <xsl:if test="not(./b:SourceType = preceding-sibling::b:Source[1]/b:SourceType)"> <!--  and (./b:SourceType = 'InternetSite')-->
			  <xsl:when test="./b:SourceType = 'InternetSite'">
			  <xsl:when test="./b:SourceType = 'Case'">
			  <!-- ... and so on ... -->
				<xsl:text /> <!-- <xsl:value-of select="./b:SourceType"/> -->

Feb 6, 2011 at 9:46 PM

If it works it's fine. You could actually remove the xsl:otherwise part as it doesn't do a thing.

Personally, I would wrap the h1 tags directly around the titles and not use them otherwise. So

 <xsl:if test="not(./b:SourceType = preceding-sibling::b:Source[1]/b:SourceType)"> <!--  and (./b:SourceType = 'InternetSite')-->
     <xsl:when test="./b:SourceType = 'InternetSite'">
     <xsl:when test="./b:SourceType = 'Case'">
     <!-- ... and so on ... -->
Feb 7, 2011 at 12:25 AM

You're version is much cleaner, I implemented that one. Thank you for all you're help yves, much appreciated.

A final heads up for anybody who reads this thread later, I achived the page break. It's not considered a 'clean' way anymore (you should not use clear=all), but it get's the job done:

<br clear="all" style="page-break-before:always" />


Feb 7, 2011 at 6:53 PM
Edited Feb 7, 2011 at 7:01 PM

One follow-up question: Is it possible to reference another format style other than the headers (h1 - h6) in the xml?

Say I created a style called 'titles' in Word (because I don't want all my sources all to get separate numbers in my index, like they would with a h1 style), can I access this one as well from html? I naturally need the h1 style with numbers for the rest of the document, so it can't be changed.

(I also use the style for other things than the bibliography, so just giving size/color etc. direct in the xml is too static)


Feb 7, 2011 at 7:22 PM

There is already such a style called MsoBibliography. It maps in Word to a localized version of the word 'bibliography'.

Feb 7, 2011 at 8:55 PM

Sorry to be slow, but I do not see this Bibliography style, you already mentioned something like it in a earlier post, but I have 18 predefined word styles, none are for the bibliography title (but one is for the citation), perhaps it's cause I have a different language word ( mentioned something similar).

Anyhow, it would be better if I could just assign my 'title' style, because:

Index, Bibliography, Internet Sites and Management Summary need to appear before the paper content _without_ a counter, so no 1., 1.1 etc. This only starts after main paper begins, then I use h1-h3 styles.

It is no problem to give 3 of the 4 a style copied from h1 style without the numbers called 'title' (or anything else, I don't care) in Word (they never 'refresh'), but Internet Sites is generated in my XML by the code above. We assigned it style <h1>, can I change it to the other style or must I manually set color, size and bold in the xml (which is very inflexible solution)?

But if Word only understands h1 - h6 as styles, then of course nothing can be done?

Feb 7, 2011 at 9:26 PM

I don't know. It depends on the HTML converter inside Word. It is that converter which does the mapping between the styles you define in your stylesheet and the ones used in your document.

What do you see when you use the style inspector (CTRL+ALT+SHIFT+S to make the style pane appear, the middle button at the bottom)? When your cursor is inside a bibliography entry, it should indicate which style is being used.

Feb 7, 2011 at 10:45 PM
Edited Feb 7, 2011 at 10:52 PM

The Title (Bibliography) has:

Paragraph: Heading 1

Text: Paragraph-Standart Text


The actual Bibliography:

Paragraph: Bibliography

Text: Paragraph-Standart Text


*freely translated. I thought perhaps there was some documentation I didn't have about html -> word, guess not though:P Tried <titel> instead of <h1>, didn't work:)

Pure guesswork, nothing to do with bibword: (edit: seems like I was wrong with this)

I have never worked with Paragraph Styles (seen them right now for the first time), so I'm not sure what they are / where they come in handy, but I'm gonna look into it, cause if I see correct, the 'text style' is only valid for the 'paragraph style'. So if I *could* define a different heading 1 style for all the page paragraphs above the main part (remove the numbers / counting), I could continue to use <h1> in the xml. Mind you, I have never seen anything like changing heading text styles depending on which part / paragraph of a word document you are in.

Feb 13, 2011 at 7:13 PM

Another brief question I found while working and can't get to work:



is my current Webpage sorting. The problem is wit the author / internetsitetitle. What happens is, all pages with an Author get displayed alphabetically, and then the pages without an author get displayed alphabetically by InternetSiteTitle.

I would like it, that these 2 are mixed. So if there is an Author, it is primery sortkey and than internettitle (incease multiple pages by same author). But if there is no author, internetsitetitle goes on the same hierarchy as the author in the sorting.

The result should look like:

Adam, a frist page, www.....

Adam, z is importantant, www.....

Clouds are nice, www....

Mark, water is nice, www....




thanks for any help!

Feb 14, 2011 at 7:40 AM

If that is the format string you are using, then they should be mixed.

Note that  it isn't even necessary to use the "|InternetSiteTitle" part as if there is no author, nothing will be returned for that part and it will automatically move on to the next element which is again the title. But that is just a 'performance' thing. The outcome will be the same.

Feb 14, 2011 at 10:20 AM

thx, you're answer made me look at it again from a different perspective, the solutions turned out to be, that I should use the namelist with id 0 (logically named sort), I assume my author:2 was return an emtpy string or something instead of null cause it has font-styles etc. defined in there, that could have been confusing the sorting.

Feb 19, 2011 at 5:21 PM

I had to do some adjustment to some code, I would be very thankful if you could say if you think this will work out, as i'm not that secure in xst.

Short summary: I needed to add DocumentFromInternetSite to my file, they are mixed in with the normal internetsites in the bibliography, and internetsites have had their special heading 'websites'. The only difference is their short citation. So I adjusted the heading xsl als follows:



<!-- when the preceding source is and internetsite or documentfrominternetsite it shouldn't make another title, as these 2 are mixed just checking for the previous sourcetype isn't enough -->
 <xsl:if test="not(./b:SourceType = preceding-sibling::b:Source[1]/b:SourceType) and preceding-sibling::b:Source[1]/b:SourceType != 'InternetSite' and preceding-sibling::b:Source[1]/b:SourceType != 'DocumentFromInternetSite'"> <xsl:choose> <!-- Depending on names, we don't know which of these 2 will be the first entry to create the title --> <xsl:when test="./b:SourceType = 'InternetSite' or ./b:SourceType = 'DocumentFromInternetSite'"> <!--<br clear="all" style="page-break-before:always" />--> <h6><xsl:text>Webseiten</xsl:text></h6> </xsl:when> <xsl:when test="./b:SourceType = 'Case'"> <h6><xsl:text>Rechtsprechung</xsl:text></h6> </xsl:when> <!-- ... and so on ... --> </xsl:choose> </xsl:if>



Oct 17, 2011 at 8:51 AM


I just write in this post a solution I found and I think its simpliest possible.

Becouse i had similar problem, i tried method proposed in this topic, and then i used something else

in "sortkey" for the first value i typed "{1}" for my primary sources, "{2}" for secondary sources and so on. It look like:


"<sortkey>{2}{%Author:0|Editor:0|"Anon."%}{%Year|"n.d."%}{%Title:a|ShortTitle:a%}</sortkey>" etc.

This solution works for me. Maybe there is some kind of problem with this, but for now i prefer to use it as categorizing method for my bibliography.

Jul 4, 2012 at 3:28 AM

Hey Khuzzuk, thanks for that code - made it so much easier.  I don't suppose you had any luck adding headings to each source type?

Thanks a lot,