How to add a new Citation & Bibliography Style to Microsoft Word?

10,982

Solution 1

It's difficult to work with the built-in style .xsl stylesheets, so the following are just some suggestions. The main difficulty is identifying the appropriate point for the change - depending on what it is, you might be able to make a single change, or you might have to make a lot of rather similar changes. This is primarily because these stylesheets try to implement a fairly large set of "small" rules. However an implementer does that, it's always going to be difficult to identify the point where changing an XSL template inside the stylesheet is going to have the right impact. Using a language that is not particularly familiar and providing no internal documentation doesn't help.

Another unfortunate problem is that you may have to provide your modified .xsl to anyone else who needs to work on your document.

But for example, I would suggest that you start by saving a copy of Chicago.xsl in the folder that you identified (the one in your user area, not the one under Program Files or Program Files (86). Call it Xhicago.xsl, perhaps.

Then, when you restart Word, you should see two identical styles listed in the relevant dropdown. Now open the .xsl in a suitable editor (I currently use Visual Studio Code here, with suitable plugins for .xml and other file types).

All that said, you could at least try the following as it may help you establish whether it's enough for your current needs.

I suggest that you start by saving a copy of Chicago.xsl in the folder that you identified (the one in your user area, not the one under Program Files or Program Files (86). Call it Xhicago.xsl, perhaps.

Then, when you restart Word, you should see two identical styles listed in the relevant dropdown. Now open a test document that already contains some citations and a bibliography, and switch between the two Chicago stylesheets using Word's dropdown. You should see no changes in the output, but Word may flicker a bit.

Open the Xhicago.xsl in a suitable editor (I currently use Visual Studio Code here, with suitable plugins for .xml and other file types).

IMO the first thing to change is the XmlVersion so you can see the difference between the original Chicago and your new one. Search for

b:XmlVersion

and you should see code like this (if you are using a significantly different version of Chicago.xsl you may see some difference from what I see).

<xsl:when test="b:XslVersion">

  <xsl:text>16</xsl:text>

</xsl:when>

Change the 16 to (say) 18 (I think Microsoft might have moved on since my version already) then save the .xsl. Here I don't generally need to close it while testing the changes. Personally I would also write an XML comment - apart from anything else, it really helps you to find the stuff you changed. e.g.

<xsl:when test="b:XslVersion">

  <!-- 20200402 changed 16 to 18 -->

  <xsl:text>18</xsl:text>

</xsl:when>

Personally I also prefer to wrap up the old code inside just in case I need it again.

Now, restart Word again and reopen your test document. You should be able to see two different "Chicago" styles in the dropdown, with two different version numbers.

Next, in the .xsl, look for

  <xsl:template name="templ_str_AndUnCap" >

and you should see a chunk of code like this:

  <xsl:template name="templ_str_AndUnCap" >
    <xsl:param name="LCID" />
    <xsl:variable name="_LCID">
      <xsl:call-template name="localLCID">
        <xsl:with-param name="LCID" select="$LCID"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:value-of select="/*/b:Locals/b:Local[@LCID=$_LCID]/b:Strings/b:AndUnCap"/>
  </xsl:template>

What this does is to set up a local variable that contains the word that the .xsl will use when it needs an "and", at least when you're using an English Language ID.

Whenever Word wants to generate the text for a citation or the whole bibliography, it passes an XML file to the .xsl. That file contains all the relevant citations, and also a whole bunch of other settings. Some of these are general settings, such as "should there be an 'and' before the final author in a list of authors", and some are settings associated with different built-in stylesheets. Further, there may be settings for many different language codes. So for example, the XML may contain "and" for English but "et" for French. As far as I know there is nowhere that lets you configure these settings - they are hard-coded in Word somewhere.

So before changing this code, you need to consider what the impact might be.

First, as far as I can tell, the word "and" is only defined in one element in the incoming XML. So if you want "and" for a list of Authors, but not for "Translators", you can't rely on the incoming XML to provide it to you. The change I am going to suggest will change "and" to "&" in every place where the .xsl references this incoming value. Further, it's not going to take any account of the language ID. But here's my suggested code:

<xsl:template name="templ_str_AndUnCap" >
    <xsl:param name="LCID" />
    <xsl:variable name="_LCID">
      <xsl:call-template name="localLCID">
        <xsl:with-param name="LCID" select="$LCID"/>
      </xsl:call-template>
    </xsl:variable>
    <!--20200402 use &amp; instead of <xsl:value-of select="/*/b:Locals/b:Local[@LCID=$_LCID]/b:Strings/b:AndUnCap"/>-->
    <xsl:text>&amp;</xsl:text>
  </xsl:template>

Now save the .xsl again. When you switch to the Chicago style and back to the Xhicago style, you should see the changes reflected in the Bibliography (although you may have to update the Bibliography). If you made any coding errors the chances are that you won't see any change, and in fact the next time you restart Word, you probably won't see the Xhicago style in the list either - Word won't load the sheet unless it's a valid .xsl and has some special templates that Word expects.

However, if everything is working and you have a Book with authors

Ionawr, Chwefror, Mawrth and Ebrill

in Chicago in the citation you should see

Ionawr, Chwefror, Mawrth and Ebrill

and in the Bibliography you should see

Ionawr, Chwefror, Mawrth, and Ebrill

In Xhicago you should see

Ionawr, Chwefror, Mawrth & Ebrill

and

Ionawr, Chwefror, Mawrth, & Ebrill

respectively.

Now I wouldn't really much like that comma after Luke, and you can probably get rid of it (again, with perhaps a wider impact than you might hope) by looking for

  <xsl:template name="templ_prop_NoCommaBeforeAnd" >

and changing the text there to

  <xsl:template name="templ_prop_NoCommaBeforeAnd" >
    <xsl:param name="LCID" />
    <xsl:variable name="_LCID">
      <xsl:call-template name="localLCID">
        <xsl:with-param name="LCID" select="$LCID"/>
      </xsl:call-template>
    </xsl:variable>
    <!-- 20200402 hard code this one
    <xsl:value-of select="/*/b:Locals/b:Local[@LCID=$_LCID]/b:General/b:NoCommaBeforeAnd"/>
    -->
    <xsl:text>yes</xsl:text>
  </xsl:template>

Save that, and test it.

Finally, getting rid of the dot between the authors and the year is problematic for even more reasons than we have discussed above. e.g. it's not necessarily a "dot before the year". e.g., what if there isn't a year? (and we haven't even discussed the situation where you have "et. al." instead of actual author names).

What may fix this for a list of book authors is to search for

<xsl:variable name="theAuthorSufixDot">

and change the code to

<xsl:variable name="theAuthorSufixDot">
  <!--this may be enough to suppress the dot between the authors and the year
  <xsl:call-template name="appendField_Dot">
    <xsl:with-param name="field" select="$theAuthorSufix"/>
  </xsl:call-template>
  -->
  <xsl:value-of select="$theAuthorSufix" />
</xsl:variable>

BTW, it's probably worth checking around to see if anyone at your uni. has already done this work. I've certainly done minor modifications for people from time to time, but I do not think getting it all right for all situations for all "cultures" is really a practical proposition without spending a lot of time on the problem. Although I think the internal structure of the XML that Word passes to the XSL may be described in the ISO 29500 standard for the .docx, I found this whole area very confusing and decided the only thing that would help would be to have a stylesheet that iterated through all the XML that Word is providing. I am sure it could be improved in a number of ways, but here is my "explore.xsl". Obviously, you can't use it like a regular sheet, but you put it in the same folder as the other .xsl files and switch to it in the usual way in Word.

Incidentally, Microsoft's documentation on what you need to put in a .xsl is quite old now. I don't think it explains all that well that some of the "options" implemented by code within the main "choice", e.g.

<xsl:when test="b:XslVersion">

were needed in earlier versions of Word, but are not needed in later ones, and vice versa. Also, at one time, the Mac version of Word supported a different FootnoteCitation layout from the normal Citation layout. However, that disappeared in Mac Word 2016 and I don't think it has come back.

Finally, you will find other .XSL files used by the Bibliography system in the Microsoft Office folders under Program Files (or the (86) version). As far as I know these are not used in producing the Citation and Bib texts, just used for some or all of the Bibliography-related dialog boxes that Word uses.

But here's that explore.xsl:

urn:schemas-microsoft-com:xslt" 
   xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" 
   xmlns:t="http://www.microsoft.com/temp">
   <xsl:output method="html" encoding="utf-8"/>

   <!--Match the root element, and dispatch to its children-->

   <xsl:template match="/">
      <!--<xsl:apply-templates select="*" />-->
      <xsl:choose>
         <xsl:when test="b:Version">
            <xsl:text>2019.10.16</xsl:text>
         </xsl:when>

         <xsl:when test="b:XslVersion">
            <xsl:text>2</xsl:text>
         </xsl:when>



         <xsl:when test="b:StyleNameLocalized">
            <xsl:text>explore</xsl:text>
         </xsl:when>

      <!--<xsl:variable name="book_Title">
         <xsl:value-of select="(b:Title)" />
      </xsl:variable>-->

         <xsl:when test="b:Citation">
            <xsl:call-template name="output-data"/>
         </xsl:when>

         <xsl:when test="b:Bibliography">
            <xsl:call-template name="output-data"/>
         </xsl:when>

      </xsl:choose>

   </xsl:template>

   <xsl:template name="output-data" >
      <html xmlns="http://www.w3.org/TR/REC-html40">
         <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
         </head>
         <body>
            <table>
               <tr>
                  <td>Name</td><td>Value</td>
               </tr>
               <xsl:apply-templates select="node()" />
            </table>
         </body>
      </html>
   </xsl:template>

    <xsl:template match="node()"> 
      <xsl:if test="text()"> 
      <tr>
         <td>
         <!--From the Answer by Daniel Haley in 
            https://stackoverflow.com/questions/953197/how-do-you-output-the-current-element-path-in-xslt -->
            <xsl:for-each select="ancestor-or-self::*">
               <xsl:value-of select="concat('/',local-name())"/>
               <!--Predicate is only output when needed.-->
               <xsl:if test="(preceding-sibling::*|following-sibling::*)[local-name()=local-name(current())]">
                  <xsl:value-of select="concat('[',count(preceding-sibling::*[local-name()=local-name(current())])+1,']')"/>
               </xsl:if>
            </xsl:for-each>
         </td>
         <td>
            <xsl:value-of select="text()"/>
         </td>
      </tr>
      </xsl:if>
      <xsl:apply-templates select="@*"/>
      <xsl:apply-templates select="node()"/>

    </xsl:template>

   <xsl:template match="@*">
      <tr>
         <td>
            <xsl:text>@</xsl:text>
            <xsl:value-of select="name(.)"/>
         </td>
         <td>
            <xsl:value-of select="text()"/>
         </td>
      </tr>
   </xsl:template>

</xsl:stylesheet>

Solution 2

I basically need to add a new Citation & Bibliography Style

You can install additional styles. One of them might be more suitable for you:

  • Associação Brasileira de Normas Técnicas (ABNT)
  • Association for Computing Machinery (ACM)
  • American Medical Society (ACS)
  • American Medical Association (AMA)
  • American Sociological Association (ASA)
  • Council of Science Editors (CSE)
  • Harvard – AGPS
  • Harvard – Anglia
  • Harvard – Exeter
  • Harvard – Leeds
  • Humana Press
  • IEEE
  • Lecture Notes in Computer Science (LNCS)
  • Modern Humanities Research Association (MHRA)
  • Nature
  • Vancouver

Source Install additional Word reference styles (Mac + Windows)

You can also use a custom style to get the exact format you want. See the following links for details:

Solution 3

My research on this suggests that this is possible via XML files. I've edited XML files before but where is the XML file of the Chicago style, for example?

It's located within Bibliography/Style within C:\Program Files (x86)\Microsoft Office\Office16\Bibliography\Style for Office 2016. The exact path will vary based on the version of Office you have installed.

Create Custom Bibliography Styles indicates everything that is required for a new citation style. Given that the process requires multiple XML files, it would be difficult to quote the link, but how you create your own style wasn't the question anyways.

Share:
10,982

Related videos on Youtube

Rok
Author by

Rok

Updated on September 18, 2022

Comments

  • Rok
    Rok almost 2 years

    In Microsoft Word, there are 12 Citation & Bibliography Styles available as shown in the following screenshot:

    The 12 Citation & Bibliography Styles available in Microsoft Word.

    However, there doesn't seem to be an easy way to add a custom or new Citation & Bibliography Style. And unfortunately, my university uses its own unique Citation and Bibliography Style, which is a slightly modified Chicago style. Basically, they use an ampersand, &, instead of "and" to refer to two authors, for example. And they put the year after the author(s) without a period in-between in the bibliography.

    So I basically need to add a new Citation & Bibliography Style to Microsoft Word that is a copy of the Chicago style but with these two slight differences.

    My research on this suggests that this is possible via XML files. I've edited XML files before but where is the XML file of the Chicago style, for example? [Edit: The path seems to be %APPDATA%\Microsoft\Bibliography)

    And which parts do I need to change in the Chicago style in order to turn the "and" between authors into an ampersand "&", and to remove the period between the author(s) and the year in the bibliography (it doesn't exist in in-line citations)?

    The APA style uses the ampersand but, unfortunately, the rest of its formatting is significantly different from Chicago, and overall Chicago is closer to my targeted style. I've tried to compare the APASixthEditionOfficeOnline.xsl and CHICAGO.XSL files to see if I can spot the differences that give me a clue as to what I need to change, given that APA uses the ampersand and Chicago uses "and", but unfortunately my level of XML knowledge, combined with the size of those files, prevented me from spotting the part(s) that need to be changed. Also, both styles put a period after the author(s) in the bibliography.

    Thanks for any help or tips with this.

  • Ramhound
    Ramhound about 4 years
    @Rok - I actually never said it would be easy to define your own citation style. You simply asked where the files were stored, which I provided, the documentation was an attempt to fully educate you on the entire process
  • Rok
    Rok about 4 years
    What the hell?! Why did anyone delete my comment of thanks?! How exactly was my comment breaking any rules?! I was just thanking yokki for an answer that obviously required an insane amount of time to research, write, and put together! What on earth is going on here?
  • Rok
    Rok about 4 years
    It would be mighty weird and awkward if superuser "prefers" that one doesn't thank the publisher of a good answer in a comment on that answer!
  • Rok
    Rok about 4 years
    Yeah, I can understand that. These comments between us right now are certainly worth deleting later on, especially because there are several of them. I just think that one comment of thanks really shouldn't be frowned upon. As long as a user isn't really posting 3 comments, for example, just to say thanks, then I think appreciation for useful answers is good and useful feedback for answer publishers, and it also "adds to the conversation". It shows, for example, that the question publisher didn't just "settle" for an answer but they liked one.
  • Rok
    Rok about 4 years
    Yeah, if they create a "frame pop-up" feature, for example, where I can hover the cursor over your name to click something to chat with you, then I could use that feature for thanks, but digging through the website menus to find the Chat feature, to begin with, then creating a room, then inviting you to it or adding your name to it ... I think that's overkill and can potentially be seen as obtrusive.