Programming in an XML-like language and making your own bibliography style

Making XML “Turing-Complete” with XSLT

What is XSLT anyways?

XSLT stands for Extensible Stylesheet Language Transformation and is a standard that defines how XML data is transformed into other textual output.
You can understand XSLT files as a template for any other output, though it is typically used for XML-compatible documents.

As Ruhsan Onder and Zeki Bayram have proven in their paper XSLT Version 2.0 Is Turing-Complete: A Purely Transformation Based Proof, XSLT is Turing-complete.

This is no XSLT guide or tutorial. XSLT is complex and very powerful, Microsoft has published a lot of resources to get started with writing XSLT documents to generate all sorts of text output; from simple websites that display XML files as tables to the actual bibliography styles.

Defining your own bibliography styles for Microsoft Word

We can leverage the flexibility of XSLT in a very common text processor: Microsoft Word.

How does it work?

Microsoft Word uses HTML to render each entry as a paragraph which then gets added to the designated place (inline or in the foot notes). In addition to that, your bibliography style controls, which fields are marked as important in Microsoft Word. This can be used to make sure all necessary fields for your style are filled and users are not left with random separators in their citations.

Define which fields are important or necessary for your style

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

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

Above is an example directly from Microsoft that shows how to control these important and necessary fields.
You define the technical names of the fields, which you will also get in the XML of your style, as text in the template. Internally Microsoft Word then executes this transformation on XML data first and receives the fields you defined.

Display your fields as part of the bibliography

When rendering your bibliography, Microsoft Word will call your transformation multiple times for each kind of display style.
Styles include the source style, which is the long bibliography typically found at the end of scientific works, and the citation which can be inline with the text or in a foot note, often containing only abbreviated information about a source.

This allows you to style each kind of display style differently. Using template matching, you can differentiate between the different requested styles:

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

<xsl:template match="b:Source[b:SourceType = 'Book']"> 
<!--Defines the output of the Citation-->
<xsl:template match="b:Citation/b:Source[b:SourceType = 'Book']"> 
   <html xmlns=""> 

I abbreviated the actual content of those templates but pay attention to the content of the match attribute of each template. As you notice, it is matching different XML content/structures which allows the template to differentiate and adapt to the changing request from Microsoft Word.

There’s a lot more

XSLT is very powerful. It allows you to define and then call common templates to eliminate redundant template content. You can define variables of more complex selections and adapt to different states like different numbers of authors. XSLT is practically a programming language and it’s very different from any other language, as it is implemented in XML. It’s easy to pick up, although somewhat verbose, but hard to master.

When looking at Microsoft’s styles (which you can always do because they are just XSLT files), you can find many instances, where an experienced programmer would be able to improve the readability, reduce redundancy and simplify the templates.

Try it out. Either copy and adapt another bibliography style or make your own, just like you need.

If there are specific requests on particular features or function of XSLT, I will probably expand this post, so leave any requests in the comments.

Reference style

I created my own bibliography style for my own use and for you as a possible reference.
It was designed to primarily adhere to the style a lecturer asked us to match based on the Harvard citation and bibliography style.
After a bunch of private iterations, I determined to release this style publicly and open-source.

It is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
This makes it easy to improve upon this style and preserve the open nature of this style. You can use it as a reference or basis but it might overwhelm you on the first look.

You can get it here:


Leave a Reply

Your email address will not be published. Required fields are marked *