| | <?xml version="1.0" encoding="utf-8"?> |
---|
| | <!-- This will mostly be a list of element names to match, along with the corresponding HTML and LaTeX handling XSLT code. --> |
---|
| | <stylesheet |
---|
| | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
---|
| | xmlns:xs="http://www.w3.org/2001/XMLSchema" |
---|
| | > |
---|
| | <stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
---|
| | xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
---|
| | |
---|
| | <!-- |
---|
| | Various "global" elements that are frequently used across all documents. Some are passed in as arguments to the stylesheet (e.g., paper number), while others are things that don't change that often, and are thus hard coded (e.g., Oracle version). |
---|
| | |
---|
| | The "strip" mode forms of the templates are for use in the context of an HTML <title> element (so the mode is only relevant to the HTML formats). Embedding HTML markup inside the <title> element causes the markup to appear verbatim in the window title, i.e., <title><em>foo</em> bar</title> will appear in the window title as "<em>foo</em> bar", not "foo bar". Putting the stylesheet into strip mode means that it will only output text nodes unless otherwise specified for a particular element. Generally the "strip" templates will simply call-template to the original, unless the original contains markup that needs to be eliminated (e.g., see OracleServer below). |
---|
| | |
---|
| | The downside of this approach, of course, is that you need "strip" mode templates for quite a lot of things, but that can't really be helped. |
---|
| | --> |
---|
| | |
---|
| | <template name="SubjectCode" match="SubjectCode"> |
---|
| | <common> |
---|
| | <xsl:value-of select="$subject-code" /> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="SubjectCode-strip" match="SubjectCode" mode="strip"> |
---|
| | <common formats="/html/xhtml/"> |
---|
| | <xsl:call-template name="SubjectCode" /> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="PaperNumber" match="PaperNumber"> |
---|
| | <common> |
---|
| | <xsl:value-of select="$paper-number" /> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="PaperNumber-strip" match="PaperNumber" mode="strip"> |
---|
| | <common formats="/html/xhtml/"> |
---|
| | <xsl:call-template name="PaperNumber" /> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="PaperCode" match="PaperCode"> |
---|
| | <common> |
---|
| | <xsl:value-of select="$subject-code" /> |
---|
| | <xsl:text> </xsl:text> |
---|
| | <xsl:value-of select="$paper-number" /> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="PaperCode-strip" match="PaperCode" mode="strip"> |
---|
| | <common formats="/html/xhtml/"> |
---|
| | <xsl:call-template name="PaperCode" /> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="PaperYear" match="PaperYear"> |
---|
| | <common> |
---|
| | <!-- |
---|
| | @offset lets us output the year +/- some integer value. |
---|
| | The input value is truncated and defaults to zero if not |
---|
| | supplied. |
---|
| | --> |
---|
| | <xsl:variable name="add"> |
---|
| | <xsl:value-of select="floor(@offset)" /> |
---|
| | <xsl:if test="not(@offset)">0</xsl:if> |
---|
| | </xsl:variable> |
---|
| | <xsl:value-of select="$paper-year + $add" /> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="PaperYear-strip" match="PaperYear" mode="strip"> |
---|
| | <common formats="/html/xhtml/"> |
---|
| | <xsl:call-template name="PaperYear" /> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="PaperPeriod" match="PaperPeriod"> |
---|
| | <common> |
---|
| | <xsl:value-of select="$paper-period" /> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="PaperPeriod-strip" match="PaperPeriod" mode="strip"> |
---|
| | <common formats="/html/xhtml/"> |
---|
| | <xsl:call-template name="PaperPeriod" /> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="OracleServer" match="OracleServer"> |
---|
| | <common formats="/latex/xelatex/">Oracle11\textit{g}</common> |
---|
| | <common formats="/html/xhtml/">Oracle11<i>g</i></common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="OracleServer-strip" match="OracleServer" mode="strip"> |
---|
| | <common formats="/html/xhtml/"> |
---|
| | <xsl:text>Oracle11g</xsl:text> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="OracleServerRelease" match="OracleServerRelease"> |
---|
| | <common>1</common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="OracleServerRelease-strip" match="OracleServerRelease" mode="strip"> |
---|
| | <common formats="/html/xhtml/"> |
---|
| | <xsl:call-template name="OracleServerRelease" /> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="OracleServerVersion" match="OracleServerVersion"> |
---|
| | <common>11.1</common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="OracleServerVersion-strip" match="OracleServerVersion" mode="strip"> |
---|
| | <common formats="/html/xhtml/"> |
---|
| | <xsl:call-template name="OracleServerVersion" /> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="Blackboard" match="Blackboard"> |
---|
| | <common> |
---|
| | <xsl:call-template name="hyperlink-internal"> |
---|
| | <xsl:with-param name="url">http://blackboard.otago.ac.nz/</xsl:with-param> |
---|
| | <xsl:with-param name="label">Blackboard</xsl:with-param> |
---|
| | </xsl:call-template> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <template name="Blackboard-strip" match="Blackboard" mode="strip"> |
---|
| | <common formats="/html/xhtml/"> |
---|
| | <xsl:text>Blackboard</xsl:text> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <!-- |
---|
| | Output a string containing the date that the document was last built. We've implemented this in two parts: |
---|
| | |
---|
| | 1. A "private" internal template that can only be called directly via call-template. |
---|
| | |
---|
| | 2. A "public" template that matches build-date elements in the document. |
---|
| | |
---|
| | |
---|
| | First, the internal template (1 above). This includes all the logic for outputting a build date string in the required form. The only time this should need to be explicitly called is for the automatic build date footers that can appear at the end of a document. |
---|
| | |
---|
| | $format: How to format the build date. |
---|
| | 'short' => Output "YYYY-MM-DD". |
---|
| | 'long' => Output "YYYY-MM-DD hh:mm:ss". [default] |
---|
| | date picture string => Output the date in the specified format (see http://www.w3.org/TR/xslt20/#date-picture-string). |
---|
| | |
---|
| | $style: The presentation style of the build date. |
---|
| | 'inline' => Output the build date inline with the surrounding text. [default] |
---|
| | 'footer' => Output the build date in a footer with some additional text, normally for inclusion at the end of a document. |
---|
| | --> |
---|
| | <template name="build-date-internal"> |
---|
| | <common> |
---|
| | <xsl:param name="format">long</xsl:param> |
---|
| | <xsl:param name="style">inline</xsl:param> |
---|
| | </common> |
---|
| | <common formats="/html/xhtml/"> |
---|
| | <xsl:choose> |
---|
| | <xsl:when test="$style = 'inline'"> |
---|
| | <xsl:call-template name="generate-build-date"> |
---|
| | <xsl:with-param name="format" select="$format" /> |
---|
| | </xsl:call-template> |
---|
| | </xsl:when> |
---|
| | <!-- We have to generate the address element as text, because we won't be closing it until much later. --> |
---|
| | <xsl:when test="$style = 'footer'"> |
---|
| | <address> |
---|
| | <xsl:value-of select="$cvs-file" /> |
---|
| | <xsl:text>, last built </xsl:text> |
---|
| | <xsl:call-template name="generate-build-date"> |
---|
| | <xsl:with-param name="format" select="$format" /> |
---|
| | </xsl:call-template> |
---|
| | </address> |
---|
| | </xsl:when> |
---|
| | <xsl:otherwise> |
---|
| | <xsl:message terminate="yes"> |
---|
| | <xsl:text>Unrecognised value "</xsl:text> |
---|
| | <xsl:value-of select="$style" /> |
---|
| | <xsl:text>" for build-date/$style.</xsl:text> |
---|
| | </xsl:message> |
---|
| | </xsl:otherwise> |
---|
| | </xsl:choose> |
---|
| | </common> |
---|
| | <common formats="/latex/xelatex/"> |
---|
| | <xsl:choose> |
---|
| | <xsl:when test="$style = 'inline'"> |
---|
| | <xsl:call-template name="generate-build-date"> |
---|
| | <xsl:with-param name="format" select="$format" /> |
---|
| | </xsl:call-template> |
---|
| | </xsl:when> |
---|
| | <xsl:when test="$style = 'footer'"> |
---|
| | <xsl:text>\vfill |
---|
| | |
---|
| | </xsl:text> |
---|
| | <xsl:text>{\scriptsize \hfill \verb+</xsl:text> |
---|
| | <xsl:value-of select="$cvs-file" /> |
---|
| | <xsl:text>, last built </xsl:text> |
---|
| | <xsl:call-template name="generate-build-date"> |
---|
| | <xsl:with-param name="format" select="$format" /> |
---|
| | </xsl:call-template> |
---|
| | <xsl:text>+} |
---|
| | |
---|
| | </xsl:text> |
---|
| | </xsl:when> |
---|
| | <xsl:otherwise> |
---|
| | <xsl:message terminate="yes"> |
---|
| | <xsl:text>Unrecognised value "</xsl:text> |
---|
| | <xsl:value-of select="$style" /> |
---|
| | <xsl:text>" for build-date/$style.</xsl:text> |
---|
| | </xsl:message> |
---|
| | </xsl:otherwise> |
---|
| | </xsl:choose> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <!-- |
---|
| | Second, the "public" template. This is essentially just a wrapper around the internal template, with some additional logic to handle differences between LaTeX and HTML handling. |
---|
| | |
---|
| | In particular, we need to consider the case where /document/@auto-latex-build-date = "no", which suppresses the final build-date footer in generated LaTeX documents (which is generated by the internal template above). This is needed to resolve issues with weird footer placement due to floating items like tables and figures. The build date can then be explicitly inserted, if desired, using a build-date element in the document, which will be process by the public template below. |
---|
| | |
---|
| | This suppression doesn't apply to HTML, so the final auto-generated build-date footer will always be produced in HTML documents, regardless. We therefore want to suppress the processing of explicit build-date elements in HTML documents, otherwise we'll end up with more or less the inverse of the LaTeX situation: build-date footers in weird locations within the document (and probably ill-formed HTML to boot). |
---|
| | |
---|
| | This template therefore suppresses calls to the internal template where applicable. |
---|
| | |
---|
| | @format: How to format the build date. |
---|
| | 'short' => Output "YYYY-MM-DD hh:mm:ss". [default] |
---|
| | 'long' => Output "Last built: YYYY-MM-DD hh:mm:ss". |
---|
| | date picture string => Output the date in the specified format (see http://www.w3.org/TR/xslt20/#date-picture-string). |
---|
| | |
---|
| | @style: The presentation style of the build date. |
---|
| | 'inline' => Output the build date inline with the surrounding text. [default] |
---|
| | 'footer' => Output the build date in a footer, normally for inclusion at the end of a document. |
---|
| | --> |
---|
| | <template name="build-date" match="build-date"> |
---|
| | <common formats="/html/xhtml/"> |
---|
| | <xsl:choose> |
---|
| | <xsl:when test="( @style = 'footer' ) and ( /document/@auto-latex-build-date = 'no' )" /> |
---|
| | <xsl:otherwise> |
---|
| | <xsl:call-template name="build-date-internal"> |
---|
| | <xsl:with-param name="format" select="@format" /> |
---|
| | <xsl:with-param name="style" select="@style" /> |
---|
| | </xsl:call-template> |
---|
| | </xsl:otherwise> |
---|
| | </xsl:choose> |
---|
| | </common> |
---|
| | <common formats="/latex/xelatex/"> |
---|
| | <xsl:call-template name="build-date-internal"> |
---|
| | <xsl:with-param name="format" select="@format" /> |
---|
| | <xsl:with-param name="style" select="@style" /> |
---|
| | </xsl:call-template> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <!-- |
---|
| | Finally, a utility template to modularise the generation of the actual date value, as it's identical for all formats. |
---|
| | |
---|
| | $format: How to format the build date. |
---|
| | 'short' => Output "YYYY-MM-DD hh:mm:ss". [default] |
---|
| | 'long' => Output "Last built: YYYY-MM-DD hh:mm:ss". |
---|
| | date picture string => Output the date in the specified format (see http://www.w3.org/TR/xslt20/#date-picture-string). |
---|
| | --> |
---|
| | <template name="generate-build-date"> |
---|
| | <common> |
---|
| | <xsl:param name="format">short</xsl:param> |
---|
| | |
---|
| | <xsl:choose> |
---|
| | <xsl:when test="$format = 'short'"> |
---|
| | <xsl:value-of select="format-dateTime( $date-built, '[Y,4]-[M,2]-[D,2]' )" /> |
---|
| | </xsl:when> |
---|
| | <xsl:when test="$format = 'long'"> |
---|
| | <xsl:value-of select="format-dateTime( $date-built, '[Y,4]-[M,2]-[D,2] [H,2]:[m,2]:[s,2]' )" /> |
---|
| | </xsl:when> |
---|
| | <!-- Assume it's a date picture string otherwise. --> |
---|
| | <xsl:otherwise> |
---|
| | <xsl:value-of select="format-dateTime( $date-built, $format )" /> |
---|
| | </xsl:otherwise> |
---|
| | </xsl:choose> |
---|
| | </common> |
---|
| | </template> |
---|
| | --> |
---|
| | <include href="modules/global-elements.xml" /> |
---|
| | |
---|
| | <!-- |
---|
| | Output a string containing the date that the document was last built. |
---|
| | --> |
---|
| | <include href="modules/build-date.xml" /> |
---|
| | |
---|
| | |
---|
| | <!-- |
---|
| | Plain paragraph. |
---|
| |
---|
| | |
---|
| | <!-- |
---|
| | Format numbers. |
---|
| | --> |
---|
| | <template name="number" match="number"> |
---|
| | <!-- LaTeX just uses the siunitx package. --> |
---|
| | <common formats="/latex/xelatex/"> |
---|
| | <xsl:text>\num{</xsl:text> |
---|
| | <xsl:apply-templates /> |
---|
| | <xsl:text>}</xsl:text> |
---|
| | </common> |
---|
| | <common formats="/html/xhtml/"> |
---|
| | <xsl:value-of select="infosci:format-number( node() )" /> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | <!-- |
---|
| | Output a number in ISO format, as follows: |
---|
| | |
---|
| | * Sign is preserved. |
---|
| | * A decimal number with no digits before the decimal point has a zero (0) inserted before the decimal point. |
---|
| | * Sequences of digits longer than four are grouped into thousands separated by a thin space. |
---|
| | |
---|
| | Note: HTML only, as LaTeX can simply use the \num macro in the siunitx package. |
---|
| | |
---|
| | $unformatted-value: The value to be formatted. |
---|
| | |
---|
| | Returns: The formatted number as a string. |
---|
| | --> |
---|
| | <function name="infosci:format-number" as="xs:string"> |
---|
| | <common formats="/html/xhtml/"> |
---|
| | <xsl:param name="unformatted-value" /> |
---|
| | <xsl:variable name="sign" select=" |
---|
| | if ( matches( $unformatted-value, '^[-+]' ) ) |
---|
| | then replace( $unformatted-value, '^([-+]).*', '$1' ) |
---|
| | else ''" /> |
---|
| | <xsl:variable name="left" select=" |
---|
| | if ( matches( $unformatted-value, '^[-+]?\d+' ) ) |
---|
| | then replace( $unformatted-value, '^[-+]?(\d+).*', '$1' ) |
---|
| | else '0'" /> |
---|
| | <xsl:variable name="right" select=" |
---|
| | if ( matches ( $unformatted-value, '^[-+]?\d*\.\d+' ) ) |
---|
| | then replace ( $unformatted-value, '^[-+]?\d*\.(\d+)', '$1' ) |
---|
| | else ''" /> |
---|
| | <xsl:sequence select=" |
---|
| | concat( $sign, |
---|
| | if ( string-length ( $left ) > 4 ) then infosci:separate-thousands( $left, 'l' ) else $left, |
---|
| | if ( $right != '' ) then '.' else '', |
---|
| | if ( string-length ( $right ) > 4 ) then infosci:separate-thousands( $right, 'r' ) else $right )" /> |
---|
| | </common> |
---|
| | </function> |
---|
| | |
---|
| | <!-- |
---|
| | Splits a sequence of digits into thousand groups, separated by thin spaces (U+2009 THIN SPACE; this appears to work in both UTF-8 and ISO-8859-1). |
---|
| | |
---|
| | $unseparated-value: The value to be formatted. |
---|
| | $mode: The "direction" in which to separate the digit sequence. |
---|
| | 'l' or 'L': the input sequence is left of the decimal point. [default] |
---|
| | 'r' or 'R': if the input sequence is right of the decimal point. |
---|
| | |
---|
| | Returns: The formatted number as a string. |
---|
| | --> |
---|
| | <function name="infosci:separate-thousands" as="xs:string"> |
---|
| | <common formats="/html/xhtml/"> |
---|
| | <xsl:param name="unseparated-value" /> |
---|
| | <xsl:param name="mode" /> |
---|
| | <!-- Sanity check. --> |
---|
| | <xsl:choose> |
---|
| | <xsl:when test="lower-case( $mode ) = 'l'" /> |
---|
| | <xsl:when test="lower-case( $mode ) = 'r'" /> |
---|
| | <xsl:otherwise> |
---|
| | <xsl:message terminate="yes">The mode parameter of function infosci:separate-thousands must be one of the values 'L', 'l', 'R' or 'r'.</xsl:message> |
---|
| | </xsl:otherwise> |
---|
| | </xsl:choose> |
---|
| | <xsl:variable name="digit-separator"> |
---|
| | <xsl:text disable-output-escaping="yes">&thinsp;</xsl:text> |
---|
| | </xsl:variable> |
---|
| | <!-- |
---|
| | Recursively subdivide the sequence. Terminate when sequence length <= 3. Note that we have to use the numeric entity for thin space rather than the character entity   because of the weird way XSLT handles character entities. Using the character entity, the HTML visibly displays as " ". |
---|
| | --> |
---|
| | <xsl:sequence select=" |
---|
| | if ( string-length( $unseparated-value ) > 3 ) |
---|
| | then concat( |
---|
| | if ( lower-case( $mode ) = 'r' ) |
---|
| | then substring( $unseparated-value, 1, 3 ) |
---|
| | else infosci:separate-thousands( substring( $unseparated-value, 1, string-length( $unseparated-value ) - 3 ), $mode ), |
---|
| | ' ', |
---|
| | if ( lower-case( $mode ) = 'r' ) |
---|
| | then infosci:separate-thousands( substring( $unseparated-value, 4 ), $mode ) |
---|
| | else substring( $unseparated-value, string-length( $unseparated-value ) - 2 ) |
---|
| | ) |
---|
| | else $unseparated-value" /> |
---|
| | </common> |
---|
| | </function> |
---|
| | <include href="modules/number-formatting.xml" /> |
---|
| | |
---|
| | |
---|
| | </stylesheet> |
---|
| | |
---|
|