Newer
Older
XML / modules / bibliography.xml
<?xml version="1.0" encoding="utf-8"?>

<!--
	Simple numbered bibliographies and reference lists (equivalent to LaTeX "plain" style biblipgraphies). We could go the whole hog and try to do something BibTeX-like, but I can't be bothered :).
-->

<stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


	<!--
		Simple numbered bibliography/references list. This is essentially similar to manually creating a LaTeX bibliography, so it's up to the author to ensure that items are correctly sorted and formatted. An important point to note is that all items will be included, regardless of whether they are cited or not. This should suffice for most of what we want to do for teaching, though.
		
		@name: The name of the section as it should appear in print. "References" is used if not specified.
	-->
	<template name="bibliography" match="bibliography">
		<common formats="/latex/xelatex/">
			<xsl:if test="@name">
				<xsl:text>\renewcommand{\refname}{</xsl:text>
				<xsl:value-of select="@name" />
				<xsl:text>}</xsl:text>
				<xsl:call-template name="newline-internal" />
			</xsl:if>
			<xsl:text>\bibliographystyle{plain}</xsl:text>
			<xsl:call-template name="newline-internal" />
			<xsl:text>\begin{thebibliography}{99}</xsl:text>
			<xsl:call-template name="newline-internal" />
			<xsl:apply-templates />
			<xsl:call-template name="newline-internal" />
			<xsl:text>\end{thebibliography}</xsl:text>
			<xsl:call-template name="newline-internal" />
		</common>
		<common formats="/html/xhtml/">
			<h1>
				<xsl:value-of select="@name" />
				<xsl:if test="not(@name)">References</xsl:if>
			</h1>
			<ol>
				<xsl:apply-templates />
			</ol>
		</common>
	</template>
	
	
	<!--
		An item within a bibliography.
		
		@label: The unique label of the bibliography item, so it can be cited. [REQUIRED]
	-->
	<template name="bibitem" match="bibliography/item">
		<common formats="/latex/xelatex/">
			<xsl:text>\bibitem{</xsl:text>
			<xsl:value-of select="@label" />
			<xsl:text>} </xsl:text>
			<xsl:apply-templates />
			<xsl:call-template name="newline-internal" />
		</common>
		<common formats="/html/xhtml/">
			<li><a id="{@label}"></a><xsl:apply-templates /></li>
		</common>
	</template>
	
	
	<!--
		A citation. To cater for multiple cited items, the items are specified using nested <item> elements rather than a "label" attribute. There must be at least one item. Each item must have a "label" attribute.
	-->
	<template name="citation" match="cite">
		<common formats="/latex/xelatex/">
			<xsl:text>\cite{</xsl:text>
			<xsl:apply-templates select="item" />
			<xsl:text>}</xsl:text>
		</common>
		<common formats="/html/xhtml/">
			<xsl:text> [</xsl:text>
			<xsl:apply-templates select="item" />
			<xsl:text>]</xsl:text>
		</common>
	</template>
	
	
	<!--
		A cited item.
		
		@label: The unique label of the cited item. [REQUIRED]
	-->
	<template name="citation-item" match="cite/item">
		<common formats="/latex/xelatex/">
			<xsl:value-of select="@label" />
			<xsl:if test="position() ne last()">
				<xsl:text>,</xsl:text>
			</xsl:if>
		</common>
		<common formats="/html/xhtml/">
			<xsl:variable name="id">
				<xsl:value-of select="@label" />
			</xsl:variable>
			<a href="#{@label}"><xsl:value-of select="1 + count(//bibliography/item[@label = $id]/preceding-sibling::*)" /></a>
			<xsl:if test="position() ne last()">
				<xsl:text>, </xsl:text>
			</xsl:if>
		</common>
	</template>


</stylesheet>