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