This project is read-only.

Ordering with accent

Aug 25, 2010 at 7:55 PM


First of all I want to thank this Site for this very good work.

I make a doctorate in anthropology in France and I really need this tool. And in France I found no similar internet site.

After several weeks on your Site that I try to translate, because my English is not very good, I created a style from one of yours.

The only mistake still remains the classification of the bibliography. In France, we classify by Author, then year. But we have many accents, and the alphabetical classification is not so good, Göle arrives after Galembert:

GÖLE, Nilüfer. 2005. « La laïcité républicaine et l'islam public ». Pouvoirs, N° 115, (4), pp. 73-86.

GALEMBERT, Claire de. 2008. « Présentation du numéro. Le voile en procès ». Droit et société, N° 68, (1), pp. 11-31.

I wanted to know how to modify this error, the only one so that the bibliography is completed.




Aug 28, 2010 at 10:16 AM

The sorting is done based on the internal algorithm of the xslt engine you are using. That is not something you can influence.

Are you using Office on a Mac? If so you might have hit on the sorting problem described in this thread:

Aug 28, 2010 at 7:38 PM

Thank you for your answer.

Indeed I am on Mac word 2008.

I read the comment which you gave. I indeed have a sortkey, the problem of the sorting is based on accents. If I transform my text and replace ö by o the name of the author is not the same.

I made tries. I transformed my bibliography into static text and I sorted out it by the option of sorting of Word. There that works because we can choose the French tongue.

So my questions :

1. Can we specify the language of sorting with a code <language id="fr">?
2. I was wondering if we could write a command line saying: "a>à> b> c> d> e> é> è" etc.
3. Or is it possible to write code that does not take into account accents for sorting and displaying it to take the original source?
4. How to create a conditional sortkey?

Thank you for your advice, I'm not a programmer and my questions may be absurd.

Aug 28, 2010 at 9:50 PM


Yes, xslt sorting allows for a lang attribute. In the code, there is something like:

<xsl:sort select="b:SortKey" data-type="text"></xsl:sort>

You could replace that by:

<xsl:sort select="b:SortKey" data-type="text" lang="fr"></xsl:sort>

But I'm not sure what you want to achieve by this. The sorting of letters is the same in English as in French as far as I know, so I doubt you will see any difference in output. As the other thread discusses, there are errors in the sorting routine of the xslt engine of Office for Mac (test showed correct results on Windows). Changing the lang attribute won't fix that.


Not without getting creative. One "creative" solution could be to translate every character to a character number pair. You would then translate an accented character to its unaccented counterpart and assign a number to its order. For example:

  • a => a0
  • à => a1
  • b => b0
  • ...
  • e => e0
  • é => e1
  • è => e2
  • ...

Then when you would sort "be", "bè", and "be", you would get:

  • be => b0e0
  • bè => b0e2
  • bé => b0e1

Which using an ordinary sort would result in be < bé < bè.

Or along the same way, translate every character to a number where all the numbers contain the same amount of digits and the number describes the sorting order. Each 'sentence' would be replaced by an extremely long sequence of digits, but those can be easily sorted.


The same holds as for 2: you could write a translate function which transforms every character to its unaccented equivalent.


What do you mean by "conditional"? Sortkeys are just like any other format strings in BibWord. So you could write a sortkey like %Author:0|Editor:0|Title% which will first try to use the author, fall back to the editor if there is no author, or eventually fall back to the title if there is no author or editor.

Sep 1, 2010 at 7:25 PM

Thank you very much for yours answers.

1. By adding the language code, the bibliography is not generated even in Word! So this is actually not the solution.

2. I tried a code like this:

<xsl:number value="a = a0"></xsl:number>

<xsl:number value="à = a1"></xsl:number>

<xsl:number value="â = a2"></xsl:number>

 etc. ...
but he adds the letters after the reference that’s all.

3. I tried an other code like this:<xsl:value-of select=translate(a , a0)”>

<xsl:value-of><xsl:value-of select=“translate(à , a1)”>

<xsl:value-of><xsl:value-of select=“translate(â , a2)”>

and this:

<xsl:value-of><xsl:value-of select=“translate(chaine, b , b0)”><xsl:value-of>

But nothing it’s happening with these examples.

4. For me a conditional sortkey, this meant, for example: if there is an 'é' classified as an 'e' command with 'if'. But this seems too complicated.

I am not a programmer and this is a bit complicated, can you tell me if I'm on the right track?

thanks, mlbl

Sep 2, 2010 at 9:47 PM

I don't have a Mac around to try things on, but I doubt that adding a "lang" attribute would break the style. I can imagine it being ignored and having no effect though.

The xslt translate function only works for character by character substitutions. It can't be used to substitute one character by 2 others. You would have to write a template function yourself to handle all characters separately. The following is an example of a full xslt file (for demo purposes) which contains such a function (very limited):

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output method="text"/>

  <xsl:template match="*">
    <xsl:call-template name="convert">
      <xsl:with-param name="input" select="text()" />

  <xsl:template name="convert">
    <xsl:param name="input"/>

    <!-- It is assumed that there is always at least 1 character. -->
    <xsl:variable name="char" select="substring($input, 1, 1)" />

      <!-- Provide a when for every special character. -->
      <xsl:when test="$char = 'â'">
      <xsl:when test="$char = 'é'">
      <xsl:when test="$char = 'è'">
      <xsl:when test="$char = 'ê'">
      <!-- Use the otherwise to handle all ordinary characters. -->
        <xsl:value-of select="$char"/>
    <!-- Repeat with the other characters. -->
    <xsl:if test="string-length($input) > 1">
      <xsl:call-template name="convert">
        <xsl:with-param name="input" select="substring($input, 2)" />

Now if you would feed the following xml file to the xslt:

<?xml version="1.0" encoding="utf-8"?>
<test>bénédict / être</test>

you would get:

b0e1n0e1d0i0c0t0 0/0 0e3t0r0e0

But you should really ask yourself if you want to go through all this trouble. Wouldn't it be mucht easier to write your entire document and live with incorrectly sorted names for now. Then, once your document is finalized, you could ask someone with Windows and Word 2007/2010 if you could use their machine for 5 minutes to fix everything.

Sep 19, 2010 at 2:28 PM


Thank you for your answers.

I react now because I tried numerous programmings of codes, even by asking for professionals' help to my work.

The answer is that the coding does not work. The only and better solution remains the import of the document under word 2007 (PC) and there there are not problems anymore of classification.

Thank you still for your help, hoping that Microsoft decides to make a corrective for MAC...