Welcome to MSDN Blogs Sign in | Join | Help

The Microsoft Office Word Team's Blog

All things Microsoft Office Word, from the Word team.
Bibliography & Citations 1011

Quick Introduction

A couple of weeks ago we posted on bibliographies and citation, and it quickly became the most commented post we've ever had. Looks like we left a lot of questions unanswered! As a result, I'm going to create a series of posts which will (hopefully) address some of the questionsaround how to create a custom bibliography style in Word 2007.

For starters, here are a few important directories to know about:

The bibliography sources you create are all listed in the following file: %APPDATA%\Microsoft\Bibliography\Sources.xml

NOTE: The \Bibliography\Sources.xml file won't exist until you create your first Bibliography source in Word 2007.

All the bibliography styles are stored in: C:\Program Files\Microsoft Office\Office12\Bibliography\Style

As a few of you have noted, yes, it is very difficult to the read the built-in XML style sheetsin our Styles directory. Many of the lines in the built-in bibliography styles are used internally by Word for specialized international cases (e.g. remembering that language X doesn't need a comma before the "and" before the last author name). Fortunately, a custom bibliography style doesn't need to be so complex. On that note, this post will walk through the steps (and XML code) needed to construct a simple custom style.

A few caveats:

I really do mean asimplecustom style. I'm not going to deal withcomplex scenarios like how to format your bibliography if someone doesn't enter a last name for the author. That sort of thing will be covered in a later post. Right now, I just want to provide a basic understanding of how bibliography styles work using a simple, easy-to-follow example.

Also, I'm not going to into the details of XML in this post. If you want to brush up on the subject, I'd suggest going herefor more information.

Building a Bibliography Style

The Setup

Let's begin creating our own bibliography style. To do so, we'll create an XML Style sheet, i.e., an .xsl file called MyBookStyle.xsl using your favorite XML editor (e.g. notepad). As the name suggests, our example is going to be a style for a book source type.At the top of the file, add the following code:

<?xml version="1.0" ?>

<!-- List of the external resources that we are referencing -->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography">

<!-- When the bibliography or citation is in your document, it's just HTML -->

<xsl:output method="html" encoding="us-ascii"/>

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

<xsl:template match="/">

<xsl:apply-templates select="*" />

</xsl:template>

 

As the comments (text in green) indicate, Word uses HTML to represent a bibliography or citation within a document. So, if you have experience using HTML, you can get pretty fancy with your output (I haven't tried blinking text yet -- and wouldn't recommend it--but if you are so inclined…J).

Most of the XML code above, is just preparation for the more interesting parts of the style. For example, you can give your style a version number to help you keep track of changes you make:

<!--Set an optional version number for this style-->

<xsl:template match="b:version">

    <xsl:text>2006.5.07</xsl:text>

</xsl:template>

Or, more importantly, you can give your style a name! Add a <xsl:template match="b:StyleName"> section that contains the name of your style. In the case of our example file, we want our custom bibliography style name, "Simple Book Style," to appear in the Style drop-down on the References tab. To do so, we'll need to add the following XML:

<!-- Defines the name of the style in the References dropdown -->

<xsl:template match="b:StyleName">

    <xsl:text>Simple Book Style</xsl:text>

</xsl:template>

This will now let your style show up with its own name in the bibliography Style dropdown box in the application.

Now for the finer details of the style. Each source type in Word(e.g. book, film, article in a periodical, etc.) has a built-in list of fields that you can use for the bibliography. To see all the fields available for a given source type, you can go to the Create New Source dialog, and check the box next to Show All Bibliography Fields.

As you can see, for a book we have the following available fields:

  • Author
  • Title
  • Year
  • City
  • State/Province
  • Country/Region
  • Publisher
  • Editor
  • Volume
  • Number of Volumes
  • Translator
  • Short Title
  • Standard Number
  • Pages
  • Edition
  • Comments

NOTE: you can edit the list of available fields for a given source type, but we'll go over that in a later post.

In the code, you can specify the fields that are important for your bibliography style. These are the fields that will be shown when the Show All Bibliography Fields is unchecked and will have red asterisks next to them when the Show All Bibliography Fields is checked. For our simple book example, I want to make sure that the author, title, year, city, and publisherare entered, so I want a red asterisk to appear next to these fields to alert the user that these are recommended fields that should be filled out:

<!-- Specifies which fields should appear in the Create Source dialog when in a collapsed state (The Show All Bibliography Fieldscheckbox is cleared) -->

<xsl:template match="b:GetImportantFields[b:SourceType = 'Book']">

    <b:ImportantFields>

    <b:ImportantField>

        <xsl:text>b:Author/b:Author/b:NameList</xsl:text>

    </b:ImportantField>

    <b:ImportantField>

        <xsl:text>b:Title</xsl:text>

    </b:ImportantField>

    <b:ImportantField>

        <xsl:text>b:Year</xsl:text>

    </b:ImportantField>

    <b:ImportantField>

        <xsl:text>b:City</xsl:text>

    </b:ImportantField>

    <b:ImportantField>

<xsl:text>b:Publisher</xsl:text>

    </b:ImportantField>

    </b:ImportantFields>

</xsl:template>

The text in the <xsl:text> tags are references to the Sources.xml file. These references pull out the data that will populate each of the fields. Feel free to take a peek at Sources.xml (%APPDATA%\Microsoft\Bibliography\Sources.xml) to get a better idea about how these references match up to what is in the xml file.

The Layout

Whew! We finally get to figure out how we want our bibliographies and citations formatted within our document. As I said before, the output for bibliographies and citations is represented as HTML in a Word document, so to define how our custom bibliography and citation styles should look in Word, we'llhave to add some HTML to our style sheet.

Suppose I want each entry in my bibliography to be formatted as so:

Last Name, First Name. (Year).Title. City: Publisher.

The HTML required to do this would be embedded in my style sheet like this:

<!-- Defines the output format for a simple Book (in the Bibliography) with important fields defined -->

<xsl:template match="b:Source[b:SourceType = 'Book']">

<!--Label the paragraph as an Office Bibliography paragraph -->

<p>

<xsl:value-of select="b:Author/b:Author/b:NameList/b:Person/b:Last"/>

<xsl:text>, </xsl:text>

<xsl:value-of select="b:Author/b:Author/b:NameList/b:Person/b:First"/>

<xsl:text>. (</xsl:text>

<xsl:value-of select="b:Year"/>

<xsl:text>). </xsl:text>

<i>

<xsl:value-of select="b:Title"/>

<xsl:text>. </xsl:text>

</i>

<xsl:value-of select="b:City"/>

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

<xsl:value-of select="b:Publisher"/>

<xsl:text>.</xsl:text>

</p>

</xsl:template>

Whenever I reference a book source in my Word document, Word will need to access this HTML so that it can display the source using the custom style, so we'll have to add a bit of code to our custom stylesheet to enable Word to do this:

<!-- Defines the output of the entire Bibliography -->

<xsl:template match="b:Bibliography">

<html xmlns="http://www.w3.org/TR/REC-html40">

    <body>

        <xsl:apply-templates select ="b:Source[b:SourceType = 'Book']">

        </xsl:apply-templates>

    </body>

    </html>

</xsl:template>

In a similar fashion, we'll need to do the same thing for the citation output. I want to follow the pattern(Author, Year)for a single citation in the document:

<!-- Defines the output of the Citation -->

<xsl:template match="b:Citation/b:Source[b:SourceType = 'Book']">

<html xmlns="http://www.w3.org/TR/REC-html40">

    <body>

<!-- Defines the output format as (Author, Year)-->

        <xsl:text>(</xsl:text>

<xsl:value-of select="b:Author/b:Author/b:NameList/b:Person/b:Last"/>

        <xsl:text>, </xsl:text>

        <xsl:value-of select="b:Year"/>

        <xsl:text>)</xsl:text>

    </body>

    </html>

</xsl:template>

Finally, close up the file with the following lines:

<xsl:template match="text()" />

</xsl:stylesheet>

All that's left is to save the file as MyBookStyle.XSL and drop it into the Styles directory (C:\Program Files\Microsoft Office\Office12\Bibliography\Style).

Meanwhile, back in Word…

Now start up Word. You'll notice that your style is listed in the Styles dropdown on the References tab!

After selecting the new style, try creating a new source using the Source Manager. All of the UI and the previews now use the style that we just defined!

Finally, the fruits of your labor can be seen in the document by inserting a citation and a bibliography on to the surface:

Here is all the code that was used in the post:

<?xml version="1.0" ?>

<!-- List of the external resources that we are referencing -->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography">

<!-- When the bibliography or citation is in your document, it's just HTML -->

<xsl:output method="html" encoding="us-ascii"/>

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

<xsl:template match="/">

<xsl:apply-templates select="*" />

</xsl:template>

<!--set an optional version number for this style-->

<xsl:template match="b:version">

    <xsl:text>2006.5.07</xsl:text>

</xsl:template>

<!-- Defines the name of the style in the References dropdown -->

<xsl:template match="b:StyleName">

    <xsl:text>Simple Book Style</xsl:text>

</xsl:template>

<!-- Specifies which fields should appear in the Create Source dialog when in a collapsed state (The Show All Bibliography Fieldscheckbox is cleared) -->

<xsl:template match="b:GetImportantFields[b:SourceType = 'Book']">

    <b:ImportantFields>

    <b:ImportantField>

        <xsl:text>b:Author/b:Author/b:NameList</xsl:text>

    </b:ImportantField>

    <b:ImportantField>

        <xsl:text>b:Title</xsl:text>

    </b:ImportantField>

    <b:ImportantField>

        <xsl:text>b:Year</xsl:text>

    </b:ImportantField>

    <b:ImportantField>

        <xsl:text>b:City</xsl:text>

    </b:ImportantField>

    <b:ImportantField>

<xsl:text>b:Publisher</xsl:text>

    </b:ImportantField>

    </b:ImportantFields>

</xsl:template>

<!-- Defines the output format for a simple Book (in the Bibliography) with important fields defined -->

<xsl:template match="b:Source[b:SourceType = 'Book']">

<!--Label the paragraph as an Office Bibliography paragraph -->

<p>

<xsl:value-of select="b:Author/b:Author/b:NameList/b:Person/b:Last"/>

<xsl:text>, </xsl:text>

<xsl:value-of select="b:Author/b:Author/b:NameList/b:Person/b:First"/>

<xsl:text>. (</xsl:text>

<xsl:value-of select="b:Year"/>

<xsl:text>). </xsl:text>

<i>

<xsl:value-of select="b:Title"/>

<xsl:text>. </xsl:text>

</i>

<xsl:value-of select="b:City"/>

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

<xsl:value-of select="b:Publisher"/>

<xsl:text>.</xsl:text>

</p>

</xsl:template>

<!-- Defines the output of the entire Bibliography -->

<xsl:template match="b:Bibliography">

<html xmlns="http://www.w3.org/TR/REC-html40">

    <body>

        <xsl:apply-templates select ="*">

        </xsl:apply-templates>

    </body>

</html>

</xsl:template>

<!-- Defines the output of the Citation -->

<xsl:template match="b:Citation/b:Source[b:SourceType = 'Book']">

<html xmlns="http://www.w3.org/TR/REC-html40">

    <body>

<!-- Defines the output format as (Author, Year)-->

        <xsl:text>(</xsl:text>

<xsl:value-of select="b:Author/b:Author/b:NameList/b:Person/b:Last"/>

        <xsl:text>, </xsl:text>

        <xsl:value-of select="b:Year"/>

        <xsl:text>)</xsl:text>

    </body>

    </html>

</xsl:template>

<xsl:template match="text()" />

</xsl:stylesheet>

-Amani

Posted: Friday, December 14, 2007 1:21 AM by wrdblog

Comments

davidacoder said:

Someone should show some heart and either program a piece of software with which one can create styles easily or convert from style definitions of other programs, like Endnote. And in fact, I think that someone should be MS, since with probably 0 serious uptake of the this feature there is most likely no real market for this right now for a third party.

# December 14, 2007 4:16 AM

Thomas M said:

I absolutely love this feature in 2007 - so easy to use and a truly fantastic addition for students! Thanks for the guide, we can now tailor our bibliography sections to fit in with "custom" guidelines!

# December 14, 2007 8:13 AM

wrdblog said:

code samples now left aligned...sorry about that.

-Jonathan (MS)

# December 14, 2007 12:28 PM

Francis said:

As it was not addressed in SP1, I've come up with a fix* for the spaces before commas issue with APA bibliographies. I simply edited the APA.XSL file included with Office (comments denote the few changes.) I hope it's not outre to post it here!

The updated APA.XSL is available at (save target to get source):

http://www.francispickering.com/APA.XSL

*Seems to work for all my references, though it's possible that unwanted spaces will appear with unusual citations.

# December 14, 2007 12:52 PM

wildeny said:

Surely this is a good improvement from the previous version. However, IMO, Zotero is much better for this purpose. It can works with MS Word, OpenOffice and Google Docs.

(For academic writing, the better choice would be using LaTeX + BidTeX and free reference management softwares).

# December 15, 2007 3:52 AM

Philip Coupar said:

Having now used this feature for creating a number of academic papers, I would like to see the following features:

Proper Harvard Referencing:

There are subtle differences between Harvard and APA, and there are people who can spot them too.  Also the lack of support for referencing the same author in the same year is a significant oversight.

Citation Import:

Many journal sites and elecronic catalog have the ability to copy the citation into other citation tools directly from their website.  It would be useful if it were possible to add the citation into word too.  I currently spend a lot of time retyping the citation into the correct fields in word.

Citation Style:

In the text it is common to State "Fayol(1952) proposes ..." or "blah, blah (Fayol, 1952)."  It would be useful if the citation tool allowed the author to optionally be placed in front of the brackets

Works Cited, and Bibliography:

a list of works cited is easy to achieve in word 2007, however producing a bibliography of works used but not cited is not so easy.  I understand the workaround to be to convert one version to text and create the other.

Reference database:  

Reference lists can become very long so a tool that allows for the grouping of references and easier edittign of reference lists would make this much easier to use.

# December 17, 2007 8:31 AM

Francis said:

Random suggestion for a next version of Word--

why not build acronym/abbreviation management on top of the citation/bibliography features? E.G., a list of acronyms in use, integration with smart tags (for automated recognition and pop-up definitions), the ability to scan the document and provide a definition in parentheses or a footnote for the first occurrence of each acronym, and a button for "insert list of abbreviations?"

# December 17, 2007 12:56 PM

davidacoder said:

Here is a question for the Word team:

Essentially the bibliography support in Word 2007 is VERY basic. On the other hand it seems pretty open, i.e. it should be possible for third parties to really extend it to something that can be used for scientific publishing in the real world. But then, I have not come across any offering from a third party that extends or builds on the support introduced in Word 2007. Are you aware of anything?

# December 18, 2007 5:09 AM

Chris Ellsworth said:

Nice tutorial!  I wish I had seen this a month ago!  I am building a stylesheet for the IEEE style standard and I would like to include a tab after the ref # so that I can allign it using tab stops.  I have tried the normal techniques for including whitespace in XSLT output, but they never seem to show up in Word.

How do you output a tab character?

# December 19, 2007 5:38 PM

BJR said:

"Now start up Word. You'll notice that your style is listed in the Styles dropdown on the References tab!"

I've copied-and-pasted the exact sample code you give at the end of the post, and I've stuck it in the ...\Bibliography\Style\ folder as instructed, but I can't seem to get the new style to show up in the dropdown in Word when I restart word. The code seems to validate fine when I open it in IE (in other words, I don't think I missed a closing brace or anything). Am I missing a step? Any idea what might be going wrong?

# December 24, 2007 4:23 AM

BJR said:

"Now start up Word. You'll notice that your style is listed in the Styles dropdown on the References tab!"

I've copied-and-pasted the exact sample code you give at the end of the post, and I've stuck it in the ...\Bibliography\Style\ folder as instructed, but I can't seem to get the new style to show up in the dropdown in Word when I restart word. The code seems to validate fine when I open it in IE (in other words, I don't think I missed a closing brace or anything). Am I missing a step? Any idea what might be going wrong?

# December 24, 2007 4:24 AM

ypchen said:

Word 2007's bibliography feature run smoothly for me until I started to use 64-bit Windows XP. I installed a fresh copy of Office 2007 after XP-64, but all functions listed in "Citations & Bibliography" were disabled except for "Search Libraries" in "Insert Citation." I never encountered such a condition while using several different machines with Office 2007 on XP-32. Can you please comment on this situation and point out some possible directions? I really would like to use this feature on my 64-bit machine. Thanks a lot!

# December 24, 2007 4:57 AM

MaskedMarvel said:

You gotta be kidding? Three pages of html code just to define one style? Is this really the best MS can do? I'm not giving up Endnote yet.

# December 27, 2007 9:55 PM

kigger said:

I don't see a way to cite my bibliographical references as footnotes or endnotes. It looks like it only works with in-text citations.

# December 27, 2007 11:08 PM

kigger said:

I also can't copy/paste information from an open Word doc into the source manager.

# December 27, 2007 11:12 PM

scleavit said:

Hi Folks,

I am trying to modify the current ISO690Nmerical.XSL file (in directory:

C:\Program Files\Microsoft Office\Office12\Bibliography\Style) in hopes of

making my own.

I have managed to change a few formats, however, am stumped on:

1.) Changing the style name from "ISO 690 Numerical" to "My Bibliography".  

I've already tried writing...

<xsl:template match="b:StyleName">

    <xsl:text>My Bibliography</xsl:text>

</xsl:template>

...but apparently the template name in the xml isn't "StyleName", does

anyone know the template name equivalent in this document?

2.) Changing the order of the "Journal Article" reference type from [Title,

Author] to [Author, Title]?  I've found that "Journal Article" proves to be a

bit more difficult than the "Book" (@ ln 4500) because the Title and Author

'seemingly' appear out of nowhere, but of course, I may have been looking at

this for too long ;^D

3.) In the citations section, instead of showing multiple references as

follows (1,2,3), write (1-3) instead.

4.) If there are more than 3 authors, write "et alum" afterwards.

Any help or pointers would be much appreciated...

Happy Holidays Folks & Happy Coding!

# December 28, 2007 11:10 AM

scleavit said:

How do I remove defaulting period after the middle initial?

Your help would be greatly appreciated!

Cheers

# December 28, 2007 1:20 PM

Chris said:

Nice feature for Office 2007 but useless to me as I always need to submit articles with AMA referencing style (not available with Word 2007) and I'm not in a position to code my own.

# January 3, 2008 5:14 PM

Egbert Teeselink said:

scleavit: you can set it around line 3420. There, you'll find a piece of code that looks like

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

   <xsl:text>ISO690NR</xsl:text>

</xsl:when>

just replace that by

<!--

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

   <xsl:text>ISO690NR</xsl:text>

</xsl:when>

-->

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

   <xsl:text>Your Fancy Style Name</xsl:text>

</xsl:when> `

It seems Office first checks if there's an "OfficeStyleKey" so that it can match that to some correct localised translation, and only tries StyleName if an OfficeStyleKey transforms to nothing.

# January 5, 2008 12:00 PM

Stefan Göckeritz said:

Hi at all, happy new year.

I am having trouble with the citation thing under word 07 as well. After struggeling around with google and his/her friends for a long time I found a way to put in a TAB character, which was one of the things I was looking for.

Use the following line where you'd like to put a tab in the word document:

<xsl:text disable-output-escaping="yes"><![CDATA[&#x9;]]></xsl:text>

IAt least for me it worked right away. I hope I helped some of u folks.

cheers

# January 6, 2008 5:12 PM

Bill Beckelman said:

Word 2007 Bibliography and Citations Feature

# January 26, 2008 10:58 AM

The Microsoft Office Word Team's Blog said:

My name is Nathan Kwan. I am a PM intern on the Microsoft Word team. My internship started in early January

# April 29, 2009 8:14 PM
New Comments to this post are disabled
Page view tracker