- Added support for standalone calendar documents.
- Refactored paper-period to period-code and added period-string variable
  computed from period-code.
1 parent 3a73d76 commit 4a4b205907ad8239c7d14511779a3288cd18bd8d
nstanger authored on 9 Aug 2012
Showing 1 changed file
View
71
xml2xslt.xsl
 
<xsl-out:param name="subject-code"><xsl:text>INFO</xsl:text></xsl-out:param>
<xsl-out:param name="paper-number" />
<xsl-out:param name="paper-year" select="year-from-date( current-date() )"/>
<xsl-out:param name="paper-period" />
<xsl-out:param name="period-code" />
<xsl-out:param name="showanswers"><xsl:text>no</xsl:text></xsl-out:param>
<xsl-out:param name="base-path"><xsl:text>.</xsl:text></xsl-out:param>
<!-- Full period string corresponding to the supplied period code. -->
<xsl-out:variable name="period-string">
<xsl-out:choose>
<xsl-out:when test="$period-code = 'SS'">
<xsl-out:text>Summer School</xsl-out:text>
</xsl-out:when>
<xsl-out:when test="$period-code = 'S1'">
<xsl-out:text>Semester One</xsl-out:text>
</xsl-out:when>
<xsl-out:when test="$period-code = 'S2'">
<xsl-out:text>Semester Two</xsl-out:text>
</xsl-out:when>
<xsl-out:when test="$period-code = 'FY'">
<xsl-out:text>Full Year</xsl-out:text>
</xsl-out:when>
<xsl-out:otherwise>
<xsl-out:message terminate="yes">
<xsl-out:text>Unrecognised period code "</xsl-out:text>
<xsl-out:value-of select="$period-code" />
<xsl-out:text>".</xsl-out:text>
</xsl-out:message>
</xsl-out:otherwise>
</xsl-out:choose>
</xsl-out:variable>
<!-- The date and time when the document was last built. -->
<xsl-out:variable name="date-built" select="current-dateTime()" />
</xsl:when>
<!--
The LaTeX formats, however have a bunch of miscellaneous boilerplate that appears at the start of every documents, and requires more complex interleaving because of hyperref. Since we need to stuff this into a template later on, we define this using a callable template, so that we can do useful things like apply-templates within it (which wouldn't work if we just used a variable).
The LaTeX formats, however have a bunch of miscellaneous boilerplate that appears at the start of every document, and requires more complex interleaving because of hyperref. Since we need to stuff this into a template later on, we define this using a callable template, so that we can do useful things like apply-templates within it (which wouldn't work if we just used a variable).
-->
<xsl:when test="$target-format = 'latex'">
<xsl-out:output method="text" encoding="{$text-encoding}" media-type="text/plain" />
<xsl-out:text>https://blackboard.otago.ac.nz/bbcswebdav/courses/</xsl-out:text>
<xsl-out:value-of select="$subject-code" />
<xsl-out:value-of select="$paper-number" />
<xsl-out:text>_</xsl-out:text>
<xsl-out:value-of select="$paper-period" />
<xsl-out:value-of select="$period-code" />
<xsl-out:text>DNS_</xsl-out:text>
<xsl-out:value-of select="$paper-year" />
<xsl-out:text>/db_styles.css</xsl-out:text>
</xsl-out:attribute>
</xsl-out:text>
</xsl-out:attribute>
</xsl-out:element>
<title>
<xsl-out:apply-templates select="title" mode="preamble" />
<xsl-out:choose>
<xsl-out:when test="calendar">
<xsl-out:value-of select="$subject-code" />
<xsl-out:value-of select="$paper-number" />
<xsl-out:text> Teaching Calendar, </xsl-out:text>
<xsl-out:value-of select="$period-string" />
<xsl-out:text>, </xsl-out:text>
<xsl-out:value-of select="$paper-year" />
</xsl-out:when>
<xsl-out:otherwise>
<xsl-out:apply-templates select="title" mode="preamble" />
</xsl-out:otherwise>
</xsl-out:choose>
</title>
</head>
<body>
<xsl-out:apply-templates select="title" mode="title" />
<xsl-out:apply-templates select="due-date" mode="title" />
<xsl-out:choose>
<xsl-out:when test="calendar" />
<xsl-out:otherwise>
<xsl-out:apply-templates select="title" mode="title" />
<xsl-out:apply-templates select="due-date" mode="title" />
</xsl-out:otherwise>
</xsl-out:choose>
<xsl-out:apply-templates />
 
<!-- How best to approach this - certain elements that need special handling (e.g. title, author) shouldn't be passed through here as well. -->
<!-- How about we just match certain elements that we know can be handled safely, e.g. sections, paragraphs, ...? (...and their aliases?) -->