- Fixed up some XPath logic.
- Documented all templates.
1 parent 9ccee1c commit 290db2eb74652864040c746c25f7d8159a485856
nstanger authored on 18 Jun 2012
Showing 1 changed file
View
124
modules/paper-calendar.xml
* this is not the first row of the current week; and
* the current week is the first week in the calendar; or
* the immediately preceding week /is/ a holiday.
(YOUR HEAD ASPLODE.)
(YOUR HEAD A SPLODE)
-->
<xsl:if test=" child::section
and ( ( ( count( ../preceding-sibling::week ) > 0 )
and ( not( ../preceding-sibling::week[1]/@holiday ) )
* this is not the last row of the current week; and
* the current week is the last week in the calendar; or
* the immediately following week /is/ a holiday.
(YOUR HEAD ASPLODE AGAIN.)
(YOUR HEAD A SPLODE ... AGAIN)
-->
<xsl:if test=" ( ( count( ../following-sibling::week ) > 0 )
and ( not( ../following-sibling::week[1]/@holiday ) )
)
<xsl:text> \cline{4-5}</xsl:text>
</xsl:if>
<!--
Underline laboratory and tutorial cells. Logic is as above, plus a test whether this is the last row of the week. (KER-SPLODEY.)
Underline laboratory and tutorial cells. Logic is as above, plus a test whether this is the last row of the week. (KER-SPLODE)
-->
<xsl:if test=" ( position() = ancestor::calendar/@lectures-per-week )
and ( ( ( count( ../following-sibling::week ) > 0 )
and ( not( ../following-sibling::week[1]/@holiday ) )
<xsl:call-template name="newline-internal" />
</xsl:for-each>
</common>
<common formats="/html/xhtml/">
<!-- Not sure why, but this doesn't work if you just access @current directly in the if below. -->
<xsl:variable name="current" select="@current" />
<xsl:for-each select="row">
<tr>
<!-- Output the week number and dates columns. -->
<xsl:if test="position() = 1">
<!-- Week number, first row only. -->
<xsl:call-template name="generate-number-cell">
<!-- TODO: Can this be compressed using XPath? -->
<xsl:with-param name="colour">
<xsl:choose>
<xsl:when test="$current = 'yes'">red</xsl:when>
<xsl:otherwise>white</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
<xsl:with-param name="colour" select="if ( $current = 'yes' ) then 'red' else 'white'" />
<xsl:with-param name="number" select="1 + count( preceding::week[not( @holiday )] )" />
</xsl:call-template>
 
<!-- Date range, first row only. -->
<a href="{@href}"><xsl:apply-templates /></a>
</common>
</template>
 
 
<!--
<template match="">
<common formats="/latex/xelatex/">
</common>
<common formats="/html/xhtml/">
</common>
</template>
 
 
<template match="">
<common formats="/latex/xelatex/">
</common>
<common formats="/html/xhtml/">
</common>
</template>
-->
<!--
Generate a cell containing a single, dynamically-generated number, centered within the cell. We can't just use generate-content-cell for these cells, because the number doesn't exist until the point where the template is called. Generate-content-cell does have the @nodes attribute, but that expects a node list, not a scalar value. The (X)eLaTeX version of this template also uses \makebox rather than a tabular to reduce the amount of horizontal space generated (we can do this because numbers don't include line breaks), and omits the @style and @align attributes, as they're pretty much irrelevant (for now, at least).
TODO: Is it possible to refactor both templates so that there's less code duplication?
@columns: The number of columns the cell spans. [default 1]
@rows: The number of rows the cell spans. [default @lectures-per-week]
@number: The number to be output in the cell. [default 0]
(XeLaTeX) only
@column-format: A LaTeX tabular column specifiation for the cell. [default c|]
(X)HTML only
@colour: The display colour of the cell, which maps to a predefined CSS class. [default white]
-->
<template name="generate-number-cell">
<common>
<xsl:param name="columns" as="xs:integer">1</xsl:param>
<xsl:param name="rows" as="xs:integer" select="ancestor::calendar/@lectures-per-week" />
<!-- No data type for this one, as there isn't a single top-level numeric primitive type in XML Schema :(. -->
<xsl:param name="number">0</xsl:param>
</common>
<common formats="/latex/xelatex/">
<!--
-->
<xsl:param name="column-format" as="xs:string">c|</xsl:param>
 
<xsl:if test="$columns > 1">
<xsl:text>\multicolumn{</xsl:text>
</common>
<common formats="/html/xhtml/">
<xsl:param name="colour" as="xs:string">white</xsl:param>
<!-- Alignment is slightly odd in that it's done via a CSS class rather than explicitly. -->
<td class="{$colour} center calendar" colspan="{$columns}" rowspan="{$rows}">
<xsl:value-of select="$number" />
</td>
</common>
</template>
<!--
Note when using pre-code in LaTeX to provide formatting: because of the tabular environment, use the declaration forms, not the macros.
Generate a cell containing general content of some sort. In (Xe)LaTeX, the cell content is embedded within a tabular environment, as it may contain embedded line breaks. (A \shortstack would also work, but the line spacing doesn't look as nice as it does with a tabular.)
@columns: The number of columns the cell spans. [default 1]
@rows: The number of rows the cell spans. [default @lectures-per-week]
@align: The alignment of the content within the cell. [default center]
@style: Styling information for the cell.
- For (Xe)LaTeX, a string containing styling /declarations/ (e.g., \bfseries, \sffamily). You can't use the macro forms (e.g., \textbf, \textsf), because of the embedded tabular environment.
- For (X)HTML, a string containing CSS styling information. Note: use @align for cell alignment and @colour for cell colouring.
@nodes: An optional list of XML document nodes that are processed to generate the cell content. [default: all sub-nodes of the current context node]
(XeLaTeX) only
@column-format: A LaTeX tabular column specifiation for the cell. [default c|]
(X)HTML only
@colour: The display colour of the cell, which maps to a predefined CSS class. [default white]
-->
<template name="generate-content-cell">
<common>
<xsl:param name="columns" as="xs:integer">1</xsl:param>
</common>
<common formats="/latex/xelatex/">
<xsl:param name="column-format" as="xs:string">c|</xsl:param>
 
<!--
<xsl:message>
<xsl:text>////////// Value of rows = [</xsl:text>
<xsl:value-of select="$rows" />
<xsl:text>] //////////</xsl:text>
</xsl:message>
-->
<xsl:if test="$columns > 1">
<xsl:text>\multicolumn{</xsl:text>
<xsl:value-of select="$columns" />
<xsl:text>}{</xsl:text>
</common>
</template>
<!--
Generate an empty cell.
@columns: The number of columns the cell spans. [default 1]
@rows: The number of rows the cell spans. [default @lectures-per-week]
(XeLaTeX) only
@column-format: A LaTeX tabular column specifiation for the cell. [default c|]
(X)HTML only
@colour: The display colour of the cell, which maps to a predefined CSS class. [default white]
-->
<template name="generate-empty-cell">
<common>
<xsl:param name="columns" as="xs:integer">1</xsl:param>
<xsl:param name="rows" as="xs:integer" select="ancestor::calendar/@lectures-per-week" />