- Moved bibliography and multi-column layouts to separate modules.
1 parent 306178b commit a05cd325ffd4951e9cba732cadacb0b875accf84
nstanger authored on 21 Sep 2011
Showing 3 changed files
View
504
format-master.xml
<common><xsl:apply-templates /></common>
</template>
<!--
Create a layout of multiple columns across the page. By default,
columns are of equal width, but may be varied on a
column-by-column basis. Each column is totally independent of
the others, i.e., you can't have text automatically flowing from
one column to the next (yet).
@vspace: The amount of vertical space to put around the
multi-column elements. [small, medium, big, LaTeX length, NONE]
@align: Overall alignment of the columns (only relevant if the
total width of the columns is less than the page width). [LEFT,
center, right]
@width: Total width of the column set, expressed as a fraction
of the usable page width between 0 and 1 (this will be
multiplied by 100 for HTML). Individual column widths are then
expressed as a fraction of this total width. [default is 1]
-->
<template name="multi-column" match="multi-column">
<common formats="/latex/xelatex/">
<xsl:variable name="total-width">
<xsl:value-of select="1" />
<xsl:if test="@width"><xsl:value-of select="@width" /></xsl:if>
</xsl:variable>
<xsl:choose>
<xsl:when test="@vspace = 'small'">\smallskip</xsl:when>
<xsl:when test="@vspace = 'medium'">\medskip</xsl:when>
<xsl:when test="@vspace = 'big'">\bigskip</xsl:when>
<xsl:when test="@vspace">\vskip<xsl:value-of select="@vspace" /></xsl:when>
</xsl:choose>
\noindent
<xsl:if test="@align">
<xsl:text>\begin{</xsl:text>
<xsl:choose>
<xsl:when test="(@align = 'left') or (@align = 'right')">
<xsl:text>flush</xsl:text><xsl:value-of select="@align" />
</xsl:when>
<xsl:when test="(@align = 'center') or (@align = 'centre')">
<xsl:text>center</xsl:text>
</xsl:when>
</xsl:choose>
<xsl:text>}</xsl:text>
</xsl:if>
<xsl:apply-templates>
<xsl:with-param name="default-width">
<xsl:value-of select="format-number($total-width div count(column),'0.00')" />
</xsl:with-param>
</xsl:apply-templates>
<xsl:if test="@align">
<xsl:text>\end{</xsl:text>
<xsl:choose>
<xsl:when test="(@align = 'left') or (@align = 'right')">
<xsl:text>flush</xsl:text><xsl:value-of select="@align" />
</xsl:when>
<xsl:when test="(@align = 'center') or (@align = 'centre')">
<xsl:text>center</xsl:text>
</xsl:when>
</xsl:choose>
<xsl:text>}</xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="@vspace = 'small'">\smallskip</xsl:when>
<xsl:when test="@vspace = 'medium'">\medskip</xsl:when>
<xsl:when test="@vspace = 'big'">\bigskip</xsl:when>
<xsl:when test="@vspace">\vskip<xsl:value-of select="@vspace" /></xsl:when>
</xsl:choose>
</common>
<common formats="/html/xhtml/">
<xsl:variable name="total-width">
<xsl:value-of select="100" />
<xsl:if test="@width"><xsl:value-of select="@width * 100" /></xsl:if>
</xsl:variable>
<xsl:if test="@vspace"><br /></xsl:if>
<table border="0" width="{$total-width}%">
<xsl:if test="@align">
<xsl:attribute name="align">
<xsl:value-of select="@align" />
</xsl:attribute>
</xsl:if>
<tr>
<xsl:apply-templates>
<xsl:with-param name="default-width">
<xsl:value-of select="round($total-width div count(column))" />
</xsl:with-param>
</xsl:apply-templates>
</tr>
</table>
<xsl:if test="@vspace"><br /></xsl:if>
</common>
</template>
<!--
A column within a multi-column element.
$default-width: The default width of the column, expressed as a
fraction of the total column set width. This is calculated by
the <multi-column> template and should be 1/n of the column set
width, where n is the number of columns.
@width: The width of this particular column (overrides the
default). This should be expressed as a fraction between 0 and 1
(which is then multipled by 100 for HTML). Make sure that all
widths add up!
@align: How each individual column is to be aligned internally.
-->
<template name="multi-column-column" match="multi-column/column">
<common formats="/latex/xelatex/">
<xsl:param name="default-width">1</xsl:param>
<xsl:text>\begin{minipage}{</xsl:text>
<xsl:choose>
<xsl:when test="@width"><xsl:value-of select="@width" /></xsl:when>
<xsl:otherwise><xsl:value-of select="$default-width" /></xsl:otherwise>
</xsl:choose>
<xsl:text>\columnwidth}</xsl:text>
<xsl:if test="@align">
<xsl:text>\begin{</xsl:text>
<xsl:choose>
<xsl:when test="(@align = 'left') or (@align = 'right')">
<xsl:text>flush</xsl:text><xsl:value-of select="@align" />
</xsl:when>
<xsl:when test="(@align = 'center') or (@align = 'centre')">
<xsl:text>center</xsl:text>
</xsl:when>
</xsl:choose>
<xsl:text>}</xsl:text>
</xsl:if>
<xsl:apply-templates />
<xsl:if test="@align">
<xsl:text>\end{</xsl:text>
<xsl:choose>
<xsl:when test="(@align = 'left') or (@align = 'right')">
<xsl:text>flush</xsl:text><xsl:value-of select="@align" />
</xsl:when>
<xsl:when test="(@align = 'center') or (@align = 'centre')">
<xsl:text>center</xsl:text>
</xsl:when>
</xsl:choose>
<xsl:text>}</xsl:text>
</xsl:if>
<xsl:text>\end{minipage}</xsl:text>
</common>
<common formats="/html/xhtml/">
<xsl:param name="default-width">100</xsl:param>
<td>
<xsl:attribute name="width">
<xsl:choose>
<xsl:when test="@width"><xsl:value-of select="@width * 100" /></xsl:when>
<xsl:otherwise><xsl:value-of select="$default-width" /></xsl:otherwise>
</xsl:choose>
<xsl:text>%</xsl:text>
</xsl:attribute>
<xsl:if test="@align">
<xsl:attribute name="align">
<xsl:value-of select="@align" />
</xsl:attribute>
</xsl:if>
<xsl:apply-templates />
</td>
</common>
</template>
<!-- Multi-column page layouts. -->
<include href="modules/multi-column.xml" />
<!--
Center stuff on the page.
</common>
</template>
<!--
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
:) This is essentially similar to manually creating a LaTeX
bibliography, so it's up to the writer 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">
\renewcommand{\refname}{<xsl:value-of select="@name" />}
</xsl:if>
\bibliographystyle{plain}
\begin{thebibliography}{99}
<xsl:apply-templates />
\end{thebibliography}
</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/">\bibitem{<xsl:value-of select="@label" />} <xsl:apply-templates /></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/">\cite{<xsl:apply-templates select="item" />}</common>
<common formats="/html/xhtml/">
<xsl:variable name="id">
<xsl:value-of select="@label" />
</xsl:variable>
<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() != 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() != last()"><xsl:text>, </xsl:text></xsl:if>
</common>
</template>
<!--
Format numbers.
-->
<!-- Bibliographies and reference lists. -->
<include href="modules/bibliography.xml" />
<!-- Format numbers. -->
<include href="modules/number-formatting.xml" />
 
</stylesheet>
View
85
modules/bibliography.xml 0 → 100755
<?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">
\renewcommand{\refname}{<xsl:value-of select="@name" />}
</xsl:if>
\bibliographystyle{plain}
\begin{thebibliography}{99}
<xsl:apply-templates />
\end{thebibliography}
</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/">\bibitem{<xsl:value-of select="@label" />} <xsl:apply-templates /></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/">\cite{<xsl:apply-templates select="item" />}</common>
<common formats="/html/xhtml/">
<xsl:variable name="id">
<xsl:value-of select="@label" />
</xsl:variable>
<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() != 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() != last()"><xsl:text>, </xsl:text></xsl:if>
</common>
</template>
 
</stylesheet>
View
modules/multi-column.xml 0 → 100755