GitBucket
4.21.2
Toggle navigation
Snippets
Sign in
Files
Branches
1
Releases
1
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
nigel.stanger
/
XML
Browse code
- Split cross-references and hyperlinks into separate modules.
master
1 parent
b0b537e
commit
5352bbf8d8820b7ca097e792abbba3d9b31fcc64
nstanger
authored
on 26 Sep 2011
Patch
Showing
3 changed files
format-master.xml
modules/cross-references.xml
modules/hyperlinks.xml
Ignore Space
Show notes
View
format-master.xml
<?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"> <!-- 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). --> <include href="modules/global-elements.xml" /> <!-- Output a string containing the date that the document was last built. --> <include href="modules/build-date.xml" /> <!-- Basic page layout elements: paragraphs, page breask, etc. --> <include href="modules/basic-page-elements.xml" /> <!-- Special characters. --> <include href="modules/special-characters.xml" /> <!-- Greek characters. --> <include href="modules/greek-characters.xml" /> <!-- Miscellaneous symbols. --> <include href="modules/miscellaneous-symbols.xml" /> <!-- Emoticons. --> <include href="modules/emoticons.xml" /> <!-- Mathematical operators and symbols. --> <include href="modules/mathematical-symbols.xml" /> <!-- Relational algebra operators. --> <include href="modules/relational-algebra.xml" /> <template name="LaTeX" match="LaTeX|latex"> <common formats="/latex/xelatex/">{\LaTeX}</common> <common formats="/html/xhtml/">L<sup>A</sup>T<sub>E</sub>X</common> </template> <template name="LaTeX-strip" match="LaTeX|latex" mode="strip"> <common formats="/html/xhtml/">LaTeX</common> </template> <!-- In-text "menus", e.g., for displaying things like Windows Start Menu items. --> <include href="modules/menus.xml" /> <!-- Basic text formatting (emphasis, bold, etc.). --> <include href="modules/basic-text-formatting.xml" /> <!-- Inline code and code blocks. --> <include href="modules/code-formatting.xml" /> <!-- Fonts and typefaces. --> <include href="modules/fonts.xml" /> <!-- Quoted text. --> <include href="modules/quotations.xml" /> <!-- Lists (itemised, enumerated, definition). --> <include href="modules/lists.xml" /> <!-- Question text. This only exists so that we can ensure that appropriate <p> tags are correctly inserted. If this template didn't exist, showing the answers would generate invalid HTML. The answers are enclosed in a <div class="answer">...</div>. Without this template, the answer markup ends up embedded inside <p>...</p>, which is invalid. --> <template name="question" match="question"> <common formats="/latex/xelatex/"><xsl:apply-templates /></common> <common formats="/html/xhtml/"> <xsl:choose> <!-- Check whether there are actual paragraphs inside the question. If so, let them worry about inserting the <p> tags. --> <xsl:when test="count(paragraph|para|p|question|answer|code-block) != 0"> <xsl:apply-templates /> </xsl:when> <!-- Otherwise, insert <p> tags surrounding the question content. --> <xsl:otherwise> <p><xsl:apply-templates /></p> </xsl:otherwise> </xsl:choose> </common> </template> <!-- Sample answers, which may optionally be excluded from the output. This can be done globally for all answers by setting the style sheet parameter $showanswers to "no", or it can be done locally on a question-by-question basis by setting the @hide attribute of the element to "yes". @hide: If "yes", don't include this answer in the output stream. The default is to include the answer. --> <template name="answer" match="answer"> <common formats="/latex/xelatex/"> <!-- It's nice to weed out the sample answer markup at the XSLT processing stage to make LaTeX run faster. Note that \showanswers still needs to be called so that LaTeX can format chapter headings like "Answers for ..." --> <xsl:if test="$showanswers='yes'"> \begin{answer} <xsl:apply-templates /> \end{answer} </xsl:if> </common> <common formats="/html/xhtml/"> <xsl:if test="$showanswers='yes'"> <div class="answer"> <xsl:apply-templates /> </div> </xsl:if> </common> </template> <!-- Match hidden answers and do nothing. --> <template name="hidden-answer" match="answer[@hide='yes']" /> <!-- Sections, subsections, subsubsections, ... @label: A label that can be used for cross referencing. Any value can be used, as long as it's a legal identifier in both LaTeX and HTML. @number: Whether or not to generate a section number. It makes the most logical sense for this attribute to be associated with the section element, but the section numbers are actually generated in the "section-title" template (see below). Consequently, this attribute isn't even mentioned in this template. 'yes' [default] 'no' --> <template name="section" match="section"> <common formats="/latex/xelatex/"> <xsl:apply-templates> <xsl:with-param name="label"> <xsl:value-of select="@label" /> <xsl:if test="not(@label)">THERE_IS_NO_LABEL</xsl:if> </xsl:with-param> </xsl:apply-templates> </common> <common formats="/html/xhtml/"> <xsl:if test="@label"><a id="{@label}"></a></xsl:if> <xsl:apply-templates /> </common> </template> <!-- Footnotes. --> <template name="footnote" match="footnote"> <common formats="/latex/xelatex/">\footnote{<xsl:apply-templates />}</common> <common formats="/html/xhtml/"> <a> <xsl:attribute name="name"> <xsl:text>footnote-</xsl:text> <xsl:number level="any" count="footnote" /> <xsl:text>-source</xsl:text> </xsl:attribute> <xsl:attribute name="href"> <xsl:text>#footnote-</xsl:text> <xsl:number level="any" count="footnote" /> <xsl:text>-target</xsl:text> </xsl:attribute> <xsl:text>[</xsl:text> <xsl:number level="any" count="footnote" /> <xsl:text>]</xsl:text> </a> </common> </template> <!-- This is only required for HTML, as LaTeX does it all for you. --> <template name="footnote-list" match="footnote" mode="list"> <common formats="/html/xhtml/"> <p> <a> <xsl:attribute name="name"> <xsl:text>footnote-</xsl:text> <xsl:number level="any" count="footnote" /> <xsl:text>-target</xsl:text> </xsl:attribute> <sup> <xsl:text>[</xsl:text> <xsl:number level="any" count="footnote" /> <xsl:text>]</xsl:text> </sup> </a> <xsl:text> </xsl:text> <xsl:apply-templates /> <xsl:text> </xsl:text> <!-- Provide a back link to the original footnote marker. --> <a> <xsl:attribute name="href"> <xsl:text>#footnote-</xsl:text> <xsl:number level="any" count="footnote" /> <xsl:text>-source</xsl:text> </xsl:attribute> <xsl:text>[Back]</xsl:text> </a> </p> </common> </template> <!-- Document preamble stuff: title, author, date. --> <template name="preamble-title" match="document/title" mode="preamble"> <common formats="/latex/xelatex/"> <xsl:text>\title{</xsl:text> <xsl:if test="/document/@class = 'assignment'"> <xsl:if test="$showanswers='yes'">Sample Solution for </xsl:if> <xsl:call-template name="PaperCode" /> <xsl:text> Assignment </xsl:text> <xsl:value-of select="/document/@sequence-number" /> <xsl:text>: \\</xsl:text> </xsl:if> <xsl:apply-templates /> <xsl:text>}</xsl:text> </common> <!-- For HTML, strip out any raw HTML formatting (e.g., emphasis), as this is not interpreted within the <title> tag, resulting in raw HTML markup in the window title. Ick. We do this by switching to "strip" mode. --> <common formats="/html/xhtml/"> <xsl:if test="( /document/@class = 'tutorial' ) or ( /document/@class = 'laboratory' ) or ( /document/@class = 'assignment' )"> <xsl:if test="$showanswers='yes'"> <xsl:choose> <xsl:when test="( /document/@class = 'tutorial' ) or ( /document/@class = 'laboratory' )"> <xsl:text>Selected Answers for </xsl:text> </xsl:when> <xsl:when test="/document/@class = 'assignment'"> <xsl:text>Sample Solution for </xsl:text> </xsl:when> </xsl:choose> </xsl:if> <xsl:call-template name="PaperCode" /> <xsl:choose> <xsl:when test="/document/@class = 'tutorial'"> <xsl:text> Tutorial </xsl:text> </xsl:when> <xsl:when test="/document/@class = 'laboratory'"> <xsl:text> Lab </xsl:text> </xsl:when> <xsl:when test="/document/@class = 'assignment'"> <xsl:text> Assignment </xsl:text> </xsl:when> </xsl:choose> <xsl:value-of select="/document/@sequence-number" /> <xsl:text>: </xsl:text> </xsl:if> <xsl:apply-templates mode="strip" /> </common> </template> <template name="preamble-author" match="document/author" mode="preamble"> <common formats="/latex/xelatex/">\author{<xsl:apply-templates />}</common> </template> <template name="preamble-date" match="document/date" mode="preamble"> <common formats="/latex/xelatex/">\date{<xsl:apply-templates />}</common> </template> <template name="document-title" match="document/title"> <!-- Need to do something sensible for LaTeX here. --> <common formats="/latex/xelatex/"> <!-- Under the LaTeX framework, the rest of the chapter title text is generated by LaTeX macros, so this is pretty simple. I think this is broken? In fact, I think that for LaTeX documents, this template isn't called at all?? Looking at xml2xslt.xsl, if the document's standalone, "preamble-title" is used, and otherwise, "chapter-title" is used. --> <xsl:if test="/document/@standalone = 'yes'"><xsl:apply-templates /></xsl:if> </common> <common formats="/html/xhtml/"> <h1> <xsl:if test="( /document/@class = 'tutorial' ) or ( /document/@class = 'laboratory' ) or ( /document/@class = 'assignment' )"> <xsl:if test="$showanswers='yes'"> <xsl:choose> <xsl:when test="( /document/@class = 'tutorial' ) or ( /document/@class = 'laboratory' )"> <xsl:text>Selected Answers for </xsl:text> </xsl:when> <xsl:when test="/document/@class = 'assignment'"> <xsl:text>Sample Solution for </xsl:text> </xsl:when> </xsl:choose> </xsl:if> <xsl:call-template name="PaperCode" /> <xsl:choose> <xsl:when test="/document/@class = 'tutorial'"> <xsl:text> Tutorial </xsl:text> </xsl:when> <xsl:when test="/document/@class = 'laboratory'"> <xsl:text> Lab </xsl:text> </xsl:when> <xsl:when test="/document/@class = 'assignment'"> <xsl:text> Assignment </xsl:text> </xsl:when> </xsl:choose> <xsl:value-of select="/document/@sequence-number" /> <xsl:text>: </xsl:text> </xsl:if> <xsl:apply-templates /> </h1> </common> </template> <!-- New template for tutorials and labs, which are essentially chapters when included in a course book, but are marked up as documents in themselves. --> <template name="chapter-title" match="document/title" mode="chapter"> <!-- TODO: For LaTeX, filling in the "INFO XXX Tutorial", etc., is currently done in the LaTeX layer in the infrastructure surrounding the \lab and \tutorial macros (i.e., it's magic). This derives from the historical origins of the handbook, and should be moved here for consistency. An initial attempt to just replace calls to \tutorial, etc., with \chapter didn't work properly, as these macros do other things as well, including internal munging of chapter handling. This Will Be Complicated :(. --> <common formats="/latex/xelatex/"> <xsl:choose> <xsl:when test="/document/@class = 'tutorial'"> <xsl:text>\tutorial{</xsl:text> </xsl:when> <xsl:when test="/document/@class = 'laboratory'"> <xsl:text>\lab{</xsl:text> </xsl:when> <xsl:otherwise> <!-- maybe we should assume that we're in a book documentclass and issue a \chapter here? --> <xsl:text>\general{</xsl:text> </xsl:otherwise> </xsl:choose> <xsl:apply-templates /> <xsl:text>}</xsl:text> </common> <common formats="/html/xhtml/"> <xsl:choose> <xsl:when test="/document/@class = 'tutorial'"> <h1><xsl:call-template name="PaperCode" /> Tutorial <xsl:value-of select="/document/@sequence-number" /><xsl:if test="$showanswers='yes'"> Sample Answers</xsl:if>: <br /><xsl:apply-templates /></h1> </xsl:when> <xsl:when test="/document/@class = 'laboratory'"> <h1><xsl:call-template name="PaperCode" /> Lab <xsl:value-of select="/document/@sequence-number" /><xsl:if test="$showanswers='yes'"> Sample Answers</xsl:if>: <br /><xsl:apply-templates /></h1> </xsl:when> <xsl:otherwise> <h1><xsl:apply-templates /></h1> </xsl:otherwise> </xsl:choose> </common> </template> <template name="document-author" match="document/author"> <common formats="/html/xhtml/"><p><xsl:apply-templates /></p></common> </template> <template name="document-date" match="document/date" /> <!-- Generate some number of "sub"s so we can produce, e.g., "subsubsection" for LaTeX. $depth: the number of repetitions (0 to 2, which maps to 1 to 3 below due to counting ancestor section elements coming out one more than expected). --> <template name="generate-subs"> <common formats="/latex/xelatex/"> <xsl:param name="depth">1</xsl:param> <xsl:if test="$depth > 1"> <xsl:if test="$depth < 4"> <xsl:text>sub</xsl:text> </xsl:if> <xsl:call-template name="generate-subs"> <xsl:with-param name="depth" select="$depth - 1" /> </xsl:call-template> </xsl:if> </common> </template> <!-- Generate section title with nested numbering, e.g., 1.1.3. --> <template name="section-title" match="section/title"> <common formats="/latex/xelatex/"> <xsl:param name="label" /> <xsl:text>\</xsl:text> <!-- Generate the correct number of "sub"s for LaTeX. --> <xsl:call-template name="generate-subs"> <xsl:with-param name="depth" select="count( ancestor::section )" /> </xsl:call-template> <xsl:text>section</xsl:text> <!-- Unnumbered section. We reference the @number attribute of the parent section element. (We are guaranteed that the parent is a section element by the match context for this template.) --> <xsl:if test="../@number = 'no'"> <xsl:text>*</xsl:text> </xsl:if> <xsl:text>{</xsl:text> <xsl:apply-templates /><xsl:text>}</xsl:text> <xsl:if test="$label != 'THERE_IS_NO_LABEL'"> \label{<xsl:value-of select="$label" />} </xsl:if> </common> <common formats="/html/xhtml/"> <!-- The depth is used in a couple of places, so we pre-calculate it. --> <xsl:variable name="depth"> <xsl:number value="1 + count(ancestor::section)" /> <xsl:if test="1 + count(ancestor::section) > 6">6</xsl:if> </xsl:variable> <xsl:text disable-output-escaping="yes"><h</xsl:text><xsl:number value="$depth" /><xsl:text disable-output-escaping="yes">></xsl:text> <!-- Unnumbered section, as per above. Note that the sense of the test is reversed: with LaTeX we output _additional_ text to get an unnumbered section, where as with HTML, we _suppress_ the additional text (i.e., the section number, which is generated here). We also only count sections that _are_ numbered. --> <xsl:if test="not( ../@number ) or ( ../@number != 'no' )"> <xsl:number count="section[not( @number ) or ( @number != 'no' )]" level="multiple" format="1.1.1.1.1.1" /> <xsl:text> </xsl:text> </xsl:if> <xsl:apply-templates /> <xsl:text disable-output-escaping="yes"></h</xsl:text><xsl:number value="$depth" /><xsl:text disable-output-escaping="yes">></xsl:text> </common> </template> <!-- Anything inside a <metadata> is ignored completely. (More accurately, we pick bits out of it manually as required; it's only ignored by apply-templates.) If we move to using attributes of "document" for all metadata, this will become redundant. --> <template name="metadata" match="metadata"> <common> <xsl:message><xsl:text>Use of metadata element obsolete!</xsl:text></xsl:message> </common> </template> <!-- Anything inside an <omit> is also ignored completely. --> <template name="omit" match="omit" /> <!-- ...and the legacy id tags inside figures. --> <template match="figure/id" /> <template match="figure/label" /> <!-- Comments are not quite ignored completely, as they're carried through to the output document (kind of: "It is an error if instantiating the content of xsl:comment creates nodes other than text nodes.") --> <template name="comment" match="comment"> <common formats="/latex/xelatex/"> <xsl:text> \begin{comment}</xsl:text> <xsl:apply-templates /> <xsl:text>\end{comment} </xsl:text> </common> <common formats="/html/xhtml/"> <xsl:comment> <xsl:apply-templates /> </xsl:comment> </common> </template> <!-- Meta-element for items that are not yet completed. --> <template name="todo" match="todo|to-do|incomplete|check"> <common formats="/latex/xelatex/"> <xsl:text>\fbox{\textbf{!!</xsl:text> <xsl:apply-templates /> <xsl:text>!!}}</xsl:text> </common> <common formats="/html/xhtml/"> <strong style="border: 1px solid black;">!!<xsl:apply-templates />!!</strong> </common> </template> <!-- Tabular structures (LaTeX {tabular}, HTML <table>). --> <include href="modules/tabular.xml" /> <!-- Hyperlinks. --> <include href="modules/hyperlinks.xml" /> <!-- Cross-references. --> <include href="modules/cross-references.xml" /> <!-- Figures & tables (in the LaTeX sense, i.e., "floating" items). @border-placement: The style of border to place around the figure or table. 'none' [default] 'box' or: any combination of 'top', 'left', 'bottom', 'right', e.g., 'bottom, left' (not all options may be available) --> <template name="figure" match="figure"> <common formats="/latex/xelatex/"> \begin{figure}<xsl:if test="@latex-placement">[<xsl:value-of select="@latex-placement" />]</xsl:if> \centering <xsl:choose> <xsl:when test="@border-placement = 'box'"> <xsl:text>\fbox{</xsl:text> </xsl:when> <xsl:when test="contains( @border-placement, 'top' )"> <xsl:text>\hrule\medskip</xsl:text> </xsl:when> </xsl:choose> <xsl:apply-templates select="*[not(self::caption)]" /> <xsl:choose> <xsl:when test="@border-placement = 'box'"> <xsl:text>}</xsl:text> </xsl:when> <xsl:when test="contains( @border-placement, 'bottom' )"> <xsl:text>\medskip\hrule</xsl:text> </xsl:when> </xsl:choose> <xsl:if test="count(caption) != 0"> \caption{<xsl:apply-templates select="caption" />} <xsl:if test="@label">\label{<xsl:value-of select="@label" />}</xsl:if> <xsl:if test="count(id) != 0">\label{<xsl:value-of select="id" />}</xsl:if> </xsl:if> \end{figure} </common> <common formats="/html/xhtml/"> <div class="figure" style="text-align: center; margin-top: 2em; margin-bottom: 2em;"> <div> <xsl:attribute name="style"> <xsl:if test="@border-placement = 'box'"> <xsl:text>border: 1px solid black; padding: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'top' )"> <xsl:text>border-top: 1px solid black; padding-top: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'left' )"> <xsl:text>border-left: 1px solid black; padding-left: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'bottom' )"> <xsl:text>border-bottom: 1px solid black; padding-bottom: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'right' )"> <xsl:text>border-right: 1px solid black; padding-right: 1em; </xsl:text> </xsl:if> </xsl:attribute> <xsl:if test="@label"><a id="{@label}"></a></xsl:if> <xsl:if test="count(id) != 0"><a id="{id}"></a></xsl:if> <xsl:apply-templates select="*[not(self::caption)]" /> </div> <xsl:if test="count(caption) != 0"> <br /> <xsl:apply-templates select="caption" /> </xsl:if> </div> </common> </template> <template name="table" match="table"> <common formats="/latex/xelatex/"> \begin{table}<xsl:if test="@latex-placement">[<xsl:value-of select="@latex-placement" />]</xsl:if> \centering <xsl:choose> <!-- TODO: test this with embedded tabulars. It might not work! --> <xsl:when test="@border-placement = 'box'"> <xsl:text>\fbox{</xsl:text> </xsl:when> <xsl:when test="contains( @border-placement, 'top' )"> <xsl:text>\hrule\medskip</xsl:text> </xsl:when> </xsl:choose> <xsl:apply-templates select="*[not(self::caption)]" /> <xsl:choose> <xsl:when test="@border-placement = 'box'"> <xsl:text>}</xsl:text> </xsl:when> <xsl:when test="contains( @border-placement, 'bottom' )"> <xsl:text>\medskip\hrule</xsl:text> </xsl:when> </xsl:choose> <xsl:if test="count(caption) != 0"> \caption{<xsl:apply-templates select="caption" />} <xsl:if test="@label">\label{<xsl:value-of select="@label" />}</xsl:if> </xsl:if> \end{table} </common> <common formats="/html/xhtml/"> <div class="table" style="text-align: center; margin-top: 2em; margin-bottom: 2em;"> <div> <xsl:attribute name="style"> <xsl:if test="@border-placement = 'box'"> <xsl:text>border: 1px solid black; padding: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'top' )"> <xsl:text>border-top: 1px solid black; padding-top: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'left' )"> <xsl:text>border-left: 1px solid black; padding-left: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'bottom' )"> <xsl:text>border-bottom: 1px solid black; padding-bottom: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'right' )"> <xsl:text>border-right: 1px solid black; padding-right: 1em; </xsl:text> </xsl:if> </xsl:attribute> <xsl:if test="@label"><a id="{@label}"></a></xsl:if> <xsl:if test="count(id) != 0"><a id="{id}"></a></xsl:if> <xsl:apply-templates select="*[not(self::caption)]" /> </div> <xsl:if test="@label"><a id="{@label}"></a></xsl:if> <xsl:apply-templates select="*[not(self::caption)]" /> <xsl:if test="count(caption) != 0"> <br /> <xsl:apply-templates select="caption" /> </xsl:if> </div> </common> </template> <template name="multipart-table" match="table[count(part) > 0]"> <common formats="/latex/xelatex/"> <xsl:for-each select="part"> \begin{table}[p] \centering <xsl:choose> <!-- TODO: test this with embedded tabulars. It might not work! --> <xsl:when test="../@border-placement = 'box'"> <xsl:text>\fbox{</xsl:text> </xsl:when> <xsl:when test="contains( ../@border-placement, 'top' )"> <xsl:text>\hrule\medskip</xsl:text> </xsl:when> </xsl:choose> <xsl:apply-templates /> <xsl:choose> <xsl:when test="../@border-placement = 'box'"> <xsl:text>}</xsl:text> </xsl:when> <xsl:when test="contains( ../@border-placement, 'bottom' )"> <xsl:text>\medskip\hrule</xsl:text> </xsl:when> </xsl:choose> <xsl:if test="count(../caption) != 0"> <xsl:text>\caption{</xsl:text> <xsl:apply-templates select="../caption" /> <xsl:choose> <xsl:when test="position() > 1"> <xsl:text> \emph{(continued)}}</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text> \emph{(continues over)}}</xsl:text> <xsl:if test="../@label">\label{<xsl:value-of select="../@label" />}</xsl:if> </xsl:otherwise> </xsl:choose> <!-- Consider the possibility of labels for each part? --> <!-- <xsl:if test="@label">\label{<xsl:value-of select="@label" />}</xsl:if> --> </xsl:if> \end{table} \addtocounter{table}{-1} \clearpage </xsl:for-each> \stepcounter{table} </common> </template> <template name="figure-caption" match="figure/caption"> <common formats="/latex/xelatex/"><xsl:apply-templates /></common> <common formats="/html/xhtml/"> <p style="text-align: center;"> <strong> <xsl:text>Figure </xsl:text> <xsl:choose> <xsl:when test="$showanswers='yes'"> <xsl:number count="figure" level="any" format="1" /> </xsl:when> <xsl:otherwise> <xsl:number count="figure[not(ancestor::answer) and not(ancestor::omit) and not(ancestor::comment)]" level="any" format="1" /> </xsl:otherwise> </xsl:choose> <xsl:text>. </xsl:text> </strong> <xsl:apply-templates /> </p> </common> </template> <template name="table-caption" match="table/caption"> <common formats="/latex/xelatex/"><xsl:apply-templates /></common> <common formats="/html/xhtml/"> <p style="text-align: center;"> <strong> <xsl:text>Table </xsl:text> <xsl:choose> <xsl:when test="$showanswers='yes'"> <xsl:number count="table" level="any" format="1" /> </xsl:when> <xsl:otherwise> <xsl:number count="table[not(ancestor::answer) and not(ancestor::omit) and not(ancestor::comment)]" level="any" format="1" /> </xsl:otherwise> </xsl:choose> <xsl:text>. </xsl:text> </strong> <xsl:apply-templates /> </p> </common> </template> <!-- Images. Includes a scaling factor for LaTeX. To do: alternatively, allow defining the scaling factor by specifying what proportion of the page width the image should occupy (a la LaTeX [width] parameter). How about a <latex-attributes> element that can be used to specify \includegraphics arguments? <width keepaspectratio="yes">0.5\columnwidth</width> <height>2cm</height> <scale>0.5</scale> etc. To do: if no description is given, use the basename as the content of the ALT element. Ideally, I think we should be able to define two image formats (PDF, EPS, PNG, ...) when marking up an image: one for LaTeX output, another for HTML. Mind you, if the generation of the various formats from a single master is handled outside of the XSLT processing...? --> <!-- LaTeX images are always handled the same way regardless. --> <template name="latex-image" match="image" mode="latex"> <common formats="/latex/xelatex/"> <xsl:text>\includegraphics</xsl:text> <xsl:if test="count(latex-scaling) != 0"> <xsl:message terminate="no"><latex-scaling> element is deprecated in <image>; please use latex-options attribute instead.</xsl:message> <xsl:text>[scale=</xsl:text> <xsl:value-of select="latex-scaling" /> <xsl:text>]</xsl:text> </xsl:if> <!-- Adding general-purpose latex pass-through arguments for \includegraphics; this should eventually subsume the "scale"-only handler above. --> <!-- If providing multiple arguments, these should be comma-separated in the source XML, but do not need the enclosing square brackets. --> <xsl:if test="@latex-options"> <xsl:text>[</xsl:text> <xsl:value-of select="@latex-options" /> <xsl:text>]</xsl:text> </xsl:if> <xsl:text>{</xsl:text> <!-- Work out the full path specification for the file to be included = base-path + location (if specified) + basename. --> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <!-- Check whether the location attribute is included. --> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <!-- need to phase out "basename" as an element and switch to using an attribute --> <xsl:if test="count(basename) != 0"> <xsl:message terminate="no"><basename> element is deprecated in <image>; please use basename attribute instead.</xsl:message> <xsl:value-of select="basename" /> </xsl:if> <xsl:if test="@basename"> <xsl:value-of select="@basename" /> </xsl:if> <xsl:text>-print.</xsl:text> <!-- Figure out the image format. --> <xsl:choose> <xsl:when test="count(format) != 0"> <xsl:message terminate="no"><format> element is deprecated in <image>; please use format attribute instead.</xsl:message> <xsl:value-of select="format" /> </xsl:when> <xsl:when test="@format"> <xsl:value-of select="@format" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$image-format" /> </xsl:otherwise> </xsl:choose> <xsl:text>}</xsl:text> </common> </template> <template name="normal-image" match="image[count(provide-large-version) = 0]"> <common formats="/latex/xelatex/"><xsl:apply-templates select="." mode="latex" /></common> <common formats="/html/xhtml/"> <img class="padded" style="border-style: none;"> <xsl:attribute name="src"> <!-- Work out the full path specification for the file to be included = base-path + location (if specified) + basename. --> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <!-- Check whether the location attribute is included. --> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:value-of select="basename|@basename" /> <xsl:text>-web.</xsl:text> <xsl:choose> <!-- CME: oops, I'd originally used the "format" tag to identify the format used in the LaTeX version, not the HTML! --> <xsl:when test="count(format) != 0"> <xsl:message terminate="no"><format> element is deprecated in <image>; please use format attribute instead.</xsl:message> <xsl:value-of select="format" /> </xsl:when> <xsl:when test="@format"> <xsl:value-of select="@format" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$image-format" /> </xsl:otherwise> </xsl:choose> </xsl:attribute> <xsl:attribute name="alt"><xsl:apply-templates select="description" /></xsl:attribute> </img> </common> </template> <template name="zoomable-image" match="image[count(provide-large-version) != 0]"> <common formats="/latex/xelatex/"><xsl:apply-templates select="." mode="latex" /></common> <common formats="/html/xhtml/"> <a> <xsl:attribute name="href"> <!-- Work out the full path specification for the file to be included = base-path + location (if specified) + basename. --> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <!-- Check whether the location attribute is included. --> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:value-of select="basename|@basename" /> <xsl:text>-web-zoom.</xsl:text> <xsl:choose> <!-- CME: oops, I'd originally used the "format" tag to identify the format used in the LaTeX version, not the HTML! --> <xsl:when test="count(format) != 0"> <xsl:message terminate="no"><format> element is deprecated in <image>; please use format attribute instead.</xsl:message> <xsl:value-of select="format" /> </xsl:when> <xsl:when test="@format"> <xsl:value-of select="@format" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$image-format" /> </xsl:otherwise> </xsl:choose> </xsl:attribute> <img class="padded" style="border-style: none;"> <xsl:attribute name="src"> <!-- Work out the full path specification for the file to be included = base-path + location (if specified) + basename. --> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <!-- Check whether the location attribute is included. --> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:value-of select="basename|@basename" /> <xsl:text>-web.</xsl:text> <xsl:choose> <!-- CME: oops, I'd originally used the "format" tag to identify the format used in the LaTeX version, not the HTML! --> <xsl:when test="count(format) != 0"> <xsl:message terminate="no"><format> element is deprecated in <image>; please use format attribute instead.</xsl:message> <xsl:value-of select="format" /> </xsl:when> <xsl:when test="@format"> <xsl:value-of select="@format" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$image-format" /> </xsl:otherwise> </xsl:choose> </xsl:attribute> <xsl:attribute name="alt"> <xsl:apply-templates select="description" /> </xsl:attribute> </img> <br clear="right" /> <xsl:text>(Larger version)</xsl:text> </a> </common> </template> <!-- Include another XML/HTML/LaTeX document into the current one. If you don't specify @type, it assumes the type of document that you're currently generating (HTML or LaTeX). LaTeX documents are simply included using \input{...}. The old <latex-input> element is now deprecated. HTML documents are a little trickier, as there's no equivalent of \input{} in HTML, plus the XSLT processor always seems to generate a DOCTYPE when producing HTML, whether you want it or not, which means that you can only really include entire HTML documents, rather than HTML fragments (maybe you can turn this off?). The workaround currently is to embed the HTML document inside an <object>. A similar argument applies for plain text documents (such as code listings) that we want to include, but are externally generated and so can't just be embedded in the source XML. @type: The type of the document to be included. [optional] Valid values are: "xml" "html" [default for HTML] "latex" [default for LaTeX] "plain" (as in text/plain) @basename: Name of file to include (including suffix!). [required] @location: Path to file to include. Note that this gets a / appended to it. However, this shouldn't make any difference in normal usage. [optional] --> <template name="include-document" match="include-document"> <common> <!-- Work out the full path specification for the file to be included = base-path + location + basename. --> <xsl:variable name="file"> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:value-of select="@basename" /> </xsl:variable> </common> <common formats="/html/xhtml/"> <div> <xsl:attribute name="align"> <xsl:choose> <xsl:when test="@align"><xsl:value-of select="@align" /></xsl:when> <xsl:otherwise>left</xsl:otherwise> </xsl:choose> </xsl:attribute> <object data="{$file}"> <!-- Output text/html or text/plain as appropriate. --> <xsl:attribute name="type"> <xsl:text>text/</xsl:text> <xsl:choose> <xsl:when test="@type"><xsl:value-of select="@type" /></xsl:when> <xsl:otherwise><xsl:text>html</xsl:text></xsl:otherwise> </xsl:choose> </xsl:attribute> <xsl:attribute name="width"> <xsl:choose> <xsl:when test="@width"><xsl:value-of select="@width" /></xsl:when> <xsl:otherwise><xsl:text>100%</xsl:text></xsl:otherwise> </xsl:choose> </xsl:attribute> <xsl:attribute name="height"> <xsl:choose> <xsl:when test="@height"><xsl:value-of select="@height" /></xsl:when> <xsl:otherwise><xsl:text>100%</xsl:text></xsl:otherwise> </xsl:choose> </xsl:attribute> </object> </div> </common> <common formats="/latex/xelatex/"> <xsl:text>\</xsl:text> <!-- Note that input text files are currently verbatim'd in LaTeX. We may want to change this in future? --> <xsl:if test="@type = 'plain'"> <xsl:text>verbatim</xsl:text> </xsl:if> <xsl:text>input{</xsl:text> <xsl:value-of select="$file" /> <xsl:text>}</xsl:text> </common> </template> <!-- Note that including XML documents is currently problematic, as the document() function expects a valid XML document. Including XML fragments is impossible. XInclude will fix this, once it is widely supported (not yet). Best to avoid this completely for now. --> <template name="include-xml" match="include-document[@type='xml']"> <common> <xsl:variable name="file"> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:value-of select="@basename" /> </xsl:variable> <xsl:apply-templates select="document($file,/)" /> </common> </template> <!-- Environment setup. This enables you to define environment settings (e.g., required LaTeX packages, etc.). We normally explicitly call the sub-elements within this, so this template is empty to prevent unwanted stuff accidentally being included in the output. --> <template name="environment" match="environment" /> <!-- Load a LaTeX package. @options: Any arguments to the package. [optional] --> <template name="latex-package" match="latex-packages/package"> <common formats="/latex/xelatex/">\usepackage<xsl:if test="@options">[<xsl:value-of select="@options" />]</xsl:if>{<xsl:value-of select="." />}</common> </template> <!-- Execute a preamble LaTeX command. Use to set up things like counters, fonts, hyperref options, etc. --> <template name="latex-command" match="latex-commands/command"> <common formats="/latex/xelatex/"><xsl:value-of select="." /></common> </template> <!-- LaTeX hyphenation. A space-delimited list of hyphenated words. --> <template name="latex-hyphenation" match="latex-commands/hyphenation"> <common formats="/latex/xelatex/">\hyphenation{<xsl:value-of select="." />}</common> </template> <!-- Hmm, the following may be more complex than I thought... External environment files sort of stuff it up. Perhaps LaTeX document class stuff should be in attributes of the document element? --> <!-- Specify LaTeX document class and options. The master stylesheet specifies \documentclass[a4paper,12pt]{article}. Anything you specify here will override that completely, so be sure to set a4paper and 12pt if that's what you want. @options: The required document class options. [optional] --> <template name="latex-documentclass" match="latex-documentclass|documentclass"> <common formats="/latex/xelatex/">\documentclass[<xsl:value-of select="@options" />]{<xsl:value-of select="." />}</common> </template> <template name="latex-documentclass-options" match="latex-documentclass[@options]|documentclass[@options]"> <common formats="/latex/xelatex/">\documentclass[<xsl:value-of select="@options" />]{<xsl:value-of select="." />}</common> </template> <!-- Specify additional LaTeX document class options (i.e., in addition to the defaults). These should be a comma-separated list of the required options. These will be appended to the standard defaults (a4paper, 12pt). --> <template name="latex-document-options" match="latex-document-options"> <common formats="/latex/xelatex/"><xsl:apply-templates /></common> </template> <!-- Sometimes we might need to embed raw code to handle something tricky. --> <template name="raw-latex" match="raw-code[@format = 'latex']|raw-latex"> <common formats="/latex/xelatex/"><xsl:apply-templates /></common> </template> <!-- This can be a tricky if the document being processed declares any namespaces, as they generally end up attached to the first element of the raw HTML. I haven't discovered a workaround yet :(. --> <template name="raw-html" match="raw-code[@format = 'html']|raw-html"> <common formats="/html/xhtml/"><xsl:copy-of select="*" /></common> </template> <!-- Generate a LaTeX \input{} macro. --> <template name="latex-input" match="latex-input"> <common formats="/latex/xelatex/"> <xsl:message>Use of latex-input is deprecated. Please use include-document instead.</xsl:message> \input{<xsl:value-of select="." />} </common> </template> <!-- Conditional processing depending on the format. It may appear redundant to have two templates, but this is the only way to ensure that the LaTeX template is empty in the HTML style sheet, and vice versa. Note the assumption that all LaTeX format names include the string 'latex' and all HTML format names include the string 'html'. @format: the format under which this XML is to be processed. [required] --> <template name="process-when-latex" match="process-when[ contains( @format, 'latex' ) ]"> <common formats="/latex/xelatex/"><xsl:apply-templates /></common> </template> <template name="process-when-html" match="process-when[ contains( @format, 'html' ) ]"> <common formats="/html/xhtml/"><xsl:apply-templates /></common> </template> <!-- Basic maths stuff. Anything more complicated is... complicated. We should probably be using MathML, but we still have to mangle it into HTML regardless. @style: How to format the maths expression. Valid values are: 'inline' [default] display expression inline 'display' display expression in its own paragraph --> <template name="math-inline" match="math|math[@style='inline']"> <common formats="/latex/xelatex/">\(<xsl:apply-templates />\)</common> <common formats="/html/xhtml/"><xsl:apply-templates /></common> </template> <template name="math-display" match="math[@style='display']"> <common formats="/latex/xelatex/">\[<xsl:apply-templates />\]</common> <common formats="/html/xhtml/"><p style="text-align: center;"><xsl:apply-templates /></p></common> </template> <!-- Equation arrays --> <template name="equation-array" match="equation-array"> <common formats="/latex/xelatex/"> <xsl:text>\begin{eqnarray*} </xsl:text> <xsl:apply-templates /> <xsl:text>\end{eqnarray*}</xsl:text> </common> <common formats="/html/xhtml/"> <table class="equation" border="0" style="margin-left: auto; margin-right: auto;"><xsl:apply-templates /></table> </common> </template> <!-- Hmm, LaTeX uses "&" as separators: how do we know if there's another cell coming? Ah, but the LaTeX eqnarray can have no more than three columns, so there's no need to generalise. --> <template match="equation-array/row"> <common formats="/latex/xelatex/"> <xsl:apply-templates select="left" /><xsl:text disable-output-escaping="yes"> & </xsl:text><xsl:apply-templates select="middle" /><xsl:text disable-output-escaping="yes"> & </xsl:text><xsl:apply-templates select="right" /><xsl:text> \\ \\ </xsl:text> </common> <common formats="/html/xhtml/"> <tr><td align="right"><xsl:apply-templates select="left" /></td><td align="center"><xsl:apply-templates select="middle" /></td><td align="left"><xsl:apply-templates select="right" /></td></tr> </common> </template> <!-- Roman (upright) text inside math environments. \mathrm sounds like it's probably more correct, but doesn't retain spaces (which \textup does). --> <template name="math-text" match="text"> <common formats="/latex/xelatex/">\textup{<xsl:apply-templates />}</common> <common formats="/html/xhtml/"><xsl:apply-templates /></common> </template> <!-- Calligraphic letters (upper case only for LaTeX). --> <template name="calligraphic-text" match="calligraphic|cursive"> <common formats="/latex/xelatex/">\ensuremath{\mathcal{<xsl:apply-templates />}}</common> <common formats="/html/xhtml/"><font face="cursive"><xsl:apply-templates /></font></common> </template> <!-- Digit grouping separator character for large numbers. SI conventions say this should be a space (but we could make it a comma if desired). --> <template name="digit-group-separator" match="digit-group-separator|digitsep"> <common><xsl:call-template name="thin-space" /></common> </template> <!-- Mathematical super- and subscript. --> <template name="superscript-math" match="math//superscript"> <common formats="/latex/xelatex/">\ensuremath{^{<xsl:apply-templates />}}</common> <common formats="/html/xhtml/"><sup><xsl:apply-templates /></sup></common> </template> <template name="subscript-math" match="math//subscript"> <common formats="/latex/xelatex/">\ensuremath{_{<xsl:apply-templates />}}</common> <common formats="/html/xhtml/"><sub><xsl:apply-templates /></sub></common> </template> <!-- The equivalent of LaTeX's "log-like functions". @name: The name of the function. We assume the names used by LaTeX here, as they work out correct anyway. There's actually nothing to stop you using any name you like, except that it'll probably die horribly in LaTeX :) [required] --> <template name="log-like-function" match="function"> <common formats="/latex/xelatex/">\ensuremath{\<xsl:value-of select="@name" />}</common> <common formats="/html/xhtml/"><xsl:value-of select="@name" /></common> </template> <!-- Any mathematical variable names. --> <template name="math-variable" match="variable|var"> <common formats="/latex/xelatex/">\ensuremath{\mathit{<xsl:apply-templates />}}</common> <common formats="/html/xhtml/"><i><xsl:apply-templates /></i></common> </template> <!-- A displayed fraction. Is there a nicer way of doing this in HTML? --> <template name="math-fraction" match="fraction"> <common formats="/latex/xelatex/">\ensuremath{\frac{<xsl:apply-templates select="numerator" />}{<xsl:apply-templates select="denominator" />}}</common> <html> <sup><xsl:apply-templates select="numerator" /></sup> <xsl:text disable-output-escaping="yes">&frasl;</xsl:text> <sub><xsl:apply-templates select="denominator" /></sub> </html> <xhtml> <sup><xsl:apply-templates select="numerator" /></sup> <span class="unicode"> <!-- U+2044 FRACTION SLASH --> <xsl:text>⁄</xsl:text> </span> <sub><xsl:apply-templates select="denominator" /></sub> </xhtml> </template> <!-- Format a University paper code. These normally appear in the form "SPOD 123", i.e., a space between the subject code and the paper number. --> <template name="paper" match="paper"> <common> <xsl:apply-templates select="subject-code" /> <xsl:text> </xsl:text> <xsl:apply-templates select="paper-number" /> </common> </template> <template name="subject-code" match="paper/subject-code"> <common><xsl:apply-templates /></common> </template> <template name="paper-number" match="paper/paper-number"> <common><xsl:apply-templates /></common> </template> <!-- Multi-column page layouts. --> <include href="modules/multi-column.xml" /> <!-- Center stuff on the page. --> <template name="center" match="center|centering|centre|centring"> <common formats="/latex/xelatex/"> \begin{center} <xsl:apply-templates /> \end{center} </common> <common formats="/html/xhtml/"> <div style="text-align: center;"> <xsl:apply-templates /> </div> </common> </template> <!-- Bibliographies and reference lists. --> <include href="modules/bibliography.xml" /> <!-- Format numbers. --> <include href="modules/number-formatting.xml" /> </stylesheet>
<?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"> <!-- 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). --> <include href="modules/global-elements.xml" /> <!-- Output a string containing the date that the document was last built. --> <include href="modules/build-date.xml" /> <!-- Basic page layout elements: paragraphs, page breask, etc. --> <include href="modules/basic-page-elements.xml" /> <!-- Special characters. --> <include href="modules/special-characters.xml" /> <!-- Greek characters. --> <include href="modules/greek-characters.xml" /> <!-- Miscellaneous symbols. --> <include href="modules/miscellaneous-symbols.xml" /> <!-- Emoticons. --> <include href="modules/emoticons.xml" /> <!-- Mathematical operators and symbols. --> <include href="modules/mathematical-symbols.xml" /> <!-- Relational algebra operators. --> <include href="modules/relational-algebra.xml" /> <template name="LaTeX" match="LaTeX|latex"> <common formats="/latex/xelatex/">{\LaTeX}</common> <common formats="/html/xhtml/">L<sup>A</sup>T<sub>E</sub>X</common> </template> <template name="LaTeX-strip" match="LaTeX|latex" mode="strip"> <common formats="/html/xhtml/">LaTeX</common> </template> <!-- In-text "menus", e.g., for displaying things like Windows Start Menu items. --> <include href="modules/menus.xml" /> <!-- Basic text formatting (emphasis, bold, etc.). --> <include href="modules/basic-text-formatting.xml" /> <!-- Inline code and code blocks. --> <include href="modules/code-formatting.xml" /> <!-- Fonts and typefaces. --> <include href="modules/fonts.xml" /> <!-- Quoted text. --> <include href="modules/quotations.xml" /> <!-- Lists (itemised, enumerated, definition). --> <include href="modules/lists.xml" /> <!-- Question text. This only exists so that we can ensure that appropriate <p> tags are correctly inserted. If this template didn't exist, showing the answers would generate invalid HTML. The answers are enclosed in a <div class="answer">...</div>. Without this template, the answer markup ends up embedded inside <p>...</p>, which is invalid. --> <template name="question" match="question"> <common formats="/latex/xelatex/"><xsl:apply-templates /></common> <common formats="/html/xhtml/"> <xsl:choose> <!-- Check whether there are actual paragraphs inside the question. If so, let them worry about inserting the <p> tags. --> <xsl:when test="count(paragraph|para|p|question|answer|code-block) != 0"> <xsl:apply-templates /> </xsl:when> <!-- Otherwise, insert <p> tags surrounding the question content. --> <xsl:otherwise> <p><xsl:apply-templates /></p> </xsl:otherwise> </xsl:choose> </common> </template> <!-- Sample answers, which may optionally be excluded from the output. This can be done globally for all answers by setting the style sheet parameter $showanswers to "no", or it can be done locally on a question-by-question basis by setting the @hide attribute of the element to "yes". @hide: If "yes", don't include this answer in the output stream. The default is to include the answer. --> <template name="answer" match="answer"> <common formats="/latex/xelatex/"> <!-- It's nice to weed out the sample answer markup at the XSLT processing stage to make LaTeX run faster. Note that \showanswers still needs to be called so that LaTeX can format chapter headings like "Answers for ..." --> <xsl:if test="$showanswers='yes'"> \begin{answer} <xsl:apply-templates /> \end{answer} </xsl:if> </common> <common formats="/html/xhtml/"> <xsl:if test="$showanswers='yes'"> <div class="answer"> <xsl:apply-templates /> </div> </xsl:if> </common> </template> <!-- Match hidden answers and do nothing. --> <template name="hidden-answer" match="answer[@hide='yes']" /> <!-- Sections, subsections, subsubsections, ... @label: A label that can be used for cross referencing. Any value can be used, as long as it's a legal identifier in both LaTeX and HTML. @number: Whether or not to generate a section number. It makes the most logical sense for this attribute to be associated with the section element, but the section numbers are actually generated in the "section-title" template (see below). Consequently, this attribute isn't even mentioned in this template. 'yes' [default] 'no' --> <template name="section" match="section"> <common formats="/latex/xelatex/"> <xsl:apply-templates> <xsl:with-param name="label"> <xsl:value-of select="@label" /> <xsl:if test="not(@label)">THERE_IS_NO_LABEL</xsl:if> </xsl:with-param> </xsl:apply-templates> </common> <common formats="/html/xhtml/"> <xsl:if test="@label"><a id="{@label}"></a></xsl:if> <xsl:apply-templates /> </common> </template> <!-- Footnotes. --> <template name="footnote" match="footnote"> <common formats="/latex/xelatex/">\footnote{<xsl:apply-templates />}</common> <common formats="/html/xhtml/"> <a> <xsl:attribute name="name"> <xsl:text>footnote-</xsl:text> <xsl:number level="any" count="footnote" /> <xsl:text>-source</xsl:text> </xsl:attribute> <xsl:attribute name="href"> <xsl:text>#footnote-</xsl:text> <xsl:number level="any" count="footnote" /> <xsl:text>-target</xsl:text> </xsl:attribute> <xsl:text>[</xsl:text> <xsl:number level="any" count="footnote" /> <xsl:text>]</xsl:text> </a> </common> </template> <!-- This is only required for HTML, as LaTeX does it all for you. --> <template name="footnote-list" match="footnote" mode="list"> <common formats="/html/xhtml/"> <p> <a> <xsl:attribute name="name"> <xsl:text>footnote-</xsl:text> <xsl:number level="any" count="footnote" /> <xsl:text>-target</xsl:text> </xsl:attribute> <sup> <xsl:text>[</xsl:text> <xsl:number level="any" count="footnote" /> <xsl:text>]</xsl:text> </sup> </a> <xsl:text> </xsl:text> <xsl:apply-templates /> <xsl:text> </xsl:text> <!-- Provide a back link to the original footnote marker. --> <a> <xsl:attribute name="href"> <xsl:text>#footnote-</xsl:text> <xsl:number level="any" count="footnote" /> <xsl:text>-source</xsl:text> </xsl:attribute> <xsl:text>[Back]</xsl:text> </a> </p> </common> </template> <!-- Document preamble stuff: title, author, date. --> <template name="preamble-title" match="document/title" mode="preamble"> <common formats="/latex/xelatex/"> <xsl:text>\title{</xsl:text> <xsl:if test="/document/@class = 'assignment'"> <xsl:if test="$showanswers='yes'">Sample Solution for </xsl:if> <xsl:call-template name="PaperCode" /> <xsl:text> Assignment </xsl:text> <xsl:value-of select="/document/@sequence-number" /> <xsl:text>: \\</xsl:text> </xsl:if> <xsl:apply-templates /> <xsl:text>}</xsl:text> </common> <!-- For HTML, strip out any raw HTML formatting (e.g., emphasis), as this is not interpreted within the <title> tag, resulting in raw HTML markup in the window title. Ick. We do this by switching to "strip" mode. --> <common formats="/html/xhtml/"> <xsl:if test="( /document/@class = 'tutorial' ) or ( /document/@class = 'laboratory' ) or ( /document/@class = 'assignment' )"> <xsl:if test="$showanswers='yes'"> <xsl:choose> <xsl:when test="( /document/@class = 'tutorial' ) or ( /document/@class = 'laboratory' )"> <xsl:text>Selected Answers for </xsl:text> </xsl:when> <xsl:when test="/document/@class = 'assignment'"> <xsl:text>Sample Solution for </xsl:text> </xsl:when> </xsl:choose> </xsl:if> <xsl:call-template name="PaperCode" /> <xsl:choose> <xsl:when test="/document/@class = 'tutorial'"> <xsl:text> Tutorial </xsl:text> </xsl:when> <xsl:when test="/document/@class = 'laboratory'"> <xsl:text> Lab </xsl:text> </xsl:when> <xsl:when test="/document/@class = 'assignment'"> <xsl:text> Assignment </xsl:text> </xsl:when> </xsl:choose> <xsl:value-of select="/document/@sequence-number" /> <xsl:text>: </xsl:text> </xsl:if> <xsl:apply-templates mode="strip" /> </common> </template> <template name="preamble-author" match="document/author" mode="preamble"> <common formats="/latex/xelatex/">\author{<xsl:apply-templates />}</common> </template> <template name="preamble-date" match="document/date" mode="preamble"> <common formats="/latex/xelatex/">\date{<xsl:apply-templates />}</common> </template> <template name="document-title" match="document/title"> <!-- Need to do something sensible for LaTeX here. --> <common formats="/latex/xelatex/"> <!-- Under the LaTeX framework, the rest of the chapter title text is generated by LaTeX macros, so this is pretty simple. I think this is broken? In fact, I think that for LaTeX documents, this template isn't called at all?? Looking at xml2xslt.xsl, if the document's standalone, "preamble-title" is used, and otherwise, "chapter-title" is used. --> <xsl:if test="/document/@standalone = 'yes'"><xsl:apply-templates /></xsl:if> </common> <common formats="/html/xhtml/"> <h1> <xsl:if test="( /document/@class = 'tutorial' ) or ( /document/@class = 'laboratory' ) or ( /document/@class = 'assignment' )"> <xsl:if test="$showanswers='yes'"> <xsl:choose> <xsl:when test="( /document/@class = 'tutorial' ) or ( /document/@class = 'laboratory' )"> <xsl:text>Selected Answers for </xsl:text> </xsl:when> <xsl:when test="/document/@class = 'assignment'"> <xsl:text>Sample Solution for </xsl:text> </xsl:when> </xsl:choose> </xsl:if> <xsl:call-template name="PaperCode" /> <xsl:choose> <xsl:when test="/document/@class = 'tutorial'"> <xsl:text> Tutorial </xsl:text> </xsl:when> <xsl:when test="/document/@class = 'laboratory'"> <xsl:text> Lab </xsl:text> </xsl:when> <xsl:when test="/document/@class = 'assignment'"> <xsl:text> Assignment </xsl:text> </xsl:when> </xsl:choose> <xsl:value-of select="/document/@sequence-number" /> <xsl:text>: </xsl:text> </xsl:if> <xsl:apply-templates /> </h1> </common> </template> <!-- New template for tutorials and labs, which are essentially chapters when included in a course book, but are marked up as documents in themselves. --> <template name="chapter-title" match="document/title" mode="chapter"> <!-- TODO: For LaTeX, filling in the "INFO XXX Tutorial", etc., is currently done in the LaTeX layer in the infrastructure surrounding the \lab and \tutorial macros (i.e., it's magic). This derives from the historical origins of the handbook, and should be moved here for consistency. An initial attempt to just replace calls to \tutorial, etc., with \chapter didn't work properly, as these macros do other things as well, including internal munging of chapter handling. This Will Be Complicated :(. --> <common formats="/latex/xelatex/"> <xsl:choose> <xsl:when test="/document/@class = 'tutorial'"> <xsl:text>\tutorial{</xsl:text> </xsl:when> <xsl:when test="/document/@class = 'laboratory'"> <xsl:text>\lab{</xsl:text> </xsl:when> <xsl:otherwise> <!-- maybe we should assume that we're in a book documentclass and issue a \chapter here? --> <xsl:text>\general{</xsl:text> </xsl:otherwise> </xsl:choose> <xsl:apply-templates /> <xsl:text>}</xsl:text> </common> <common formats="/html/xhtml/"> <xsl:choose> <xsl:when test="/document/@class = 'tutorial'"> <h1><xsl:call-template name="PaperCode" /> Tutorial <xsl:value-of select="/document/@sequence-number" /><xsl:if test="$showanswers='yes'"> Sample Answers</xsl:if>: <br /><xsl:apply-templates /></h1> </xsl:when> <xsl:when test="/document/@class = 'laboratory'"> <h1><xsl:call-template name="PaperCode" /> Lab <xsl:value-of select="/document/@sequence-number" /><xsl:if test="$showanswers='yes'"> Sample Answers</xsl:if>: <br /><xsl:apply-templates /></h1> </xsl:when> <xsl:otherwise> <h1><xsl:apply-templates /></h1> </xsl:otherwise> </xsl:choose> </common> </template> <template name="document-author" match="document/author"> <common formats="/html/xhtml/"><p><xsl:apply-templates /></p></common> </template> <template name="document-date" match="document/date" /> <!-- Generate some number of "sub"s so we can produce, e.g., "subsubsection" for LaTeX. $depth: the number of repetitions (0 to 2, which maps to 1 to 3 below due to counting ancestor section elements coming out one more than expected). --> <template name="generate-subs"> <common formats="/latex/xelatex/"> <xsl:param name="depth">1</xsl:param> <xsl:if test="$depth > 1"> <xsl:if test="$depth < 4"> <xsl:text>sub</xsl:text> </xsl:if> <xsl:call-template name="generate-subs"> <xsl:with-param name="depth" select="$depth - 1" /> </xsl:call-template> </xsl:if> </common> </template> <!-- Generate section title with nested numbering, e.g., 1.1.3. --> <template name="section-title" match="section/title"> <common formats="/latex/xelatex/"> <xsl:param name="label" /> <xsl:text>\</xsl:text> <!-- Generate the correct number of "sub"s for LaTeX. --> <xsl:call-template name="generate-subs"> <xsl:with-param name="depth" select="count( ancestor::section )" /> </xsl:call-template> <xsl:text>section</xsl:text> <!-- Unnumbered section. We reference the @number attribute of the parent section element. (We are guaranteed that the parent is a section element by the match context for this template.) --> <xsl:if test="../@number = 'no'"> <xsl:text>*</xsl:text> </xsl:if> <xsl:text>{</xsl:text> <xsl:apply-templates /><xsl:text>}</xsl:text> <xsl:if test="$label != 'THERE_IS_NO_LABEL'"> \label{<xsl:value-of select="$label" />} </xsl:if> </common> <common formats="/html/xhtml/"> <!-- The depth is used in a couple of places, so we pre-calculate it. --> <xsl:variable name="depth"> <xsl:number value="1 + count(ancestor::section)" /> <xsl:if test="1 + count(ancestor::section) > 6">6</xsl:if> </xsl:variable> <xsl:text disable-output-escaping="yes"><h</xsl:text><xsl:number value="$depth" /><xsl:text disable-output-escaping="yes">></xsl:text> <!-- Unnumbered section, as per above. Note that the sense of the test is reversed: with LaTeX we output _additional_ text to get an unnumbered section, where as with HTML, we _suppress_ the additional text (i.e., the section number, which is generated here). We also only count sections that _are_ numbered. --> <xsl:if test="not( ../@number ) or ( ../@number != 'no' )"> <xsl:number count="section[not( @number ) or ( @number != 'no' )]" level="multiple" format="1.1.1.1.1.1" /> <xsl:text> </xsl:text> </xsl:if> <xsl:apply-templates /> <xsl:text disable-output-escaping="yes"></h</xsl:text><xsl:number value="$depth" /><xsl:text disable-output-escaping="yes">></xsl:text> </common> </template> <!-- Anything inside a <metadata> is ignored completely. (More accurately, we pick bits out of it manually as required; it's only ignored by apply-templates.) If we move to using attributes of "document" for all metadata, this will become redundant. --> <template name="metadata" match="metadata"> <common> <xsl:message><xsl:text>Use of metadata element obsolete!</xsl:text></xsl:message> </common> </template> <!-- Anything inside an <omit> is also ignored completely. --> <template name="omit" match="omit" /> <!-- ...and the legacy id tags inside figures. --> <template match="figure/id" /> <template match="figure/label" /> <!-- Comments are not quite ignored completely, as they're carried through to the output document (kind of: "It is an error if instantiating the content of xsl:comment creates nodes other than text nodes.") --> <template name="comment" match="comment"> <common formats="/latex/xelatex/"> <xsl:text> \begin{comment}</xsl:text> <xsl:apply-templates /> <xsl:text>\end{comment} </xsl:text> </common> <common formats="/html/xhtml/"> <xsl:comment> <xsl:apply-templates /> </xsl:comment> </common> </template> <!-- Meta-element for items that are not yet completed. --> <template name="todo" match="todo|to-do|incomplete|check"> <common formats="/latex/xelatex/"> <xsl:text>\fbox{\textbf{!!</xsl:text> <xsl:apply-templates /> <xsl:text>!!}}</xsl:text> </common> <common formats="/html/xhtml/"> <strong style="border: 1px solid black;">!!<xsl:apply-templates />!!</strong> </common> </template> <!-- Tabular structures (LaTeX {tabular}, HTML <table>). --> <include href="modules/tabular.xml" /> <!-- Hyperlinks. The content of the element is the hyperlink text. @label: A label that the hyperlink links to. The value should be an acceptable label in both LaTeX and HTML. [optional] @url: A URL that the hyperlink links to. If no link text is provided, the URL is used as the link text. [optional] --> <template name="hyperlink-label" match="hyperlink[@label and node()]"> <common formats="/latex/xelatex/">\hyperref[<xsl:value-of select="@label" />]{<xsl:apply-templates />}</common> <common formats="/html/xhtml/"><a href="#{@label}"><xsl:apply-templates /></a></common> </template> <template name="empty-hyperlink-label" match="hyperlink[@label and not(node())]"> <common> <xsl:message terminate="yes"><hyperlink> with @label must include link text.</xsl:message> </common> </template> <template name="hyperlink-url" match="hyperlink[@url and node()]"> <common formats="/latex/xelatex/">\href{<xsl:value-of select="@url" />}{<xsl:apply-templates />}</common> <common formats="/html/xhtml/"><a href="{@url}"><xsl:apply-templates /></a></common> </template> <template name="empty-hyperlink-url" match="hyperlink[@url and not(node())]"> <!-- Note: not safe to use the url package here because \url{...} is fragile. --> <common formats="/latex/xelatex/">\url{<xsl:value-of select="@url" />}</common> <common formats="/html/xhtml/"><a href="{@url}"><code><xsl:value-of select="@url" /></code></a></common> </template> <template name="hyperlink-bogus" match="hyperlink[@url and @label]" priority="2"> <common> <xsl:message terminate="yes">Cannot use both @url and @label in <hyperlink>.</xsl:message> </common> </template> <!-- Internal parameterised hyperlink template to be called by the likes of the empty Oracle documentation elements. --> <template name="hyperlink-internal" match="hyperlink" mode="hyperlink-internal"> <common> <xsl:param name="url" /> <xsl:param name="label" /> </common> <common formats="/latex/xelatex/">\href{<xsl:value-of select="$url" />}{<xsl:apply-templates select="exsl:node-set($label)" />}</common> <common formats="/html/xhtml/"><a href="{$url}"><xsl:apply-templates select="exsl:node-set($label)" /></a></common> </template> <template name="empty-hyperlink-url-internal" match="hyperlink" mode="empty-hyperlink-internal"> <common><xsl:param name="url" /></common> <common formats="/latex/xelatex/">\url{<xsl:value-of select="$url" />}</common> <common formats="/html/xhtml/"><a href="{$url}"><code><xsl:value-of select="$url" /></code></a></common> </template> <!-- A plain URL (i.e., not necessarily a hyperlink). --> <template name="url" match="url|uri|email|e-mail|email-address|e-mail-address"> <!-- Hmm, \url{...} appears to turn the URL into a non-functional link in PDF output (probably an interaction with hyperref). Not really what we want (as the link aspect is already dealt with by the <hyperlink> templates), so we'll just use \texttt{...}. --> <common formats="/latex/xelatex/">\nolinkurl{<xsl:apply-templates />}</common> <common formats="/html/xhtml/"><code><xsl:apply-templates /></code></common> </template> <!-- References. Note the distinction betwen these and hyperlinks: a reference is merely something like "see Section 2.3", and doesn't necessarily imply a hyperlink, or vice versa. @label: The label of the item that we're referencing. It must be a valid label in both LaTeX and HTML. [required] @include-pageref: If "yes", also append a page reference (LaTeX only; this is handled by the "item-page-reference" template below). --> <template name="reference" match="reference[@label]"> <common> <!-- Find the element whose label is the same as our label. --> <xsl:apply-templates select="//*[@label = current()/@label]" mode="reference" /> <xsl:if test="@include-pageref = 'yes'"> <xsl:apply-templates select="//*[@label = current()/@label]" mode="page-reference" /> </xsl:if> </common> </template> <template name="broken-reference" match="reference[not( @label )]"> <common> <xsl:message terminate="yes">Reference elements must include a label attribute.</xsl:message> </common> </template> <!-- Do a separate template for each type of referenced item; easier. --> <template name="section-reference" match="section" mode="reference"> <!-- It's probably more consistent to just use \ref* and insert "Section" ourselves rather than let LaTeX do it. --> <common formats="/latex/xelatex/"> <xsl:text>Section~\ref*{</xsl:text> <xsl:value-of select="@label" /> <xsl:text>}</xsl:text> </common> <common formats="/html/xhtml/"> <xsl:text disable-output-escaping="yes">Section&nbsp;</xsl:text> <xsl:number count="section" level="multiple" format="1.1.1.1.1.1" /> </common> </template> <template name="figure-reference" match="figure" mode="reference"> <common formats="/latex/xelatex/"> <xsl:text>Figure~\ref*{</xsl:text> <xsl:value-of select="@label" /> <xsl:text>}</xsl:text> </common> <common formats="/html/xhtml/"> <xsl:text disable-output-escaping="yes">Figure&nbsp;</xsl:text> <xsl:choose> <xsl:when test="$showanswers='yes'"> <xsl:number count="figure" level="any" format="1" /> </xsl:when> <xsl:otherwise> <xsl:number count="figure[not(ancestor::answer) and not(ancestor::omit) and not(ancestor::comment)]" level="any" format="1" /> </xsl:otherwise> </xsl:choose> </common> </template> <template name="table-reference" match="table" mode="reference"> <common formats="/latex/xelatex/"> <xsl:text>Table~\ref*{</xsl:text> <xsl:value-of select="@label" /> <xsl:text>}</xsl:text> </common> <common formats="/html/xhtml/"> <xsl:text disable-output-escaping="yes">Table&nbsp;</xsl:text> <xsl:choose> <xsl:when test="$showanswers='yes'"> <xsl:number count="table" level="any" format="1" /> </xsl:when> <xsl:otherwise> <xsl:number count="table[not(ancestor::answer) and not(ancestor::omit) and not(ancestor::comment)]" level="any" format="1" /> </xsl:otherwise> </xsl:choose> </common> </template> <!-- Standalone direct reference to a page (i.e., not associated with some other item like a figure or table). This only really makes sense in LaTeX, as HTML doesn't have page numbers. For HTML, we fudge things by inserting the string "here", which will make sense if the reference is wrapped with a hyperlink (as they usually are). --> <template name="page-reference" match="page[@label]" mode="reference"> <common formats="/latex/xelatex/"> <xsl:text>page~\pageref{</xsl:text> <xsl:value-of select="@label" /> <xsl:text>}</xsl:text> </common> <common formats="/html/xhtml/"> <xsl:text disable-output-escaping="yes">here</xsl:text> </common> </template> <!-- Common template for appended page references, as they're identical for all items except for standalone page references, which aren't included in this template. The include-pageref attribute is therefore ignored on standalone page references. --> <template name="item-page-reference" match="section|figure|table" mode="page-reference"> <common formats="/latex/xelatex/"> <xsl:text> on page~\pageref{</xsl:text> <xsl:value-of select="@label" /> <xsl:text>}</xsl:text> </common> </template> <!-- Generate a standalone label for use in direct page references. TODO: Hmm, this seems to generate the correct page number in LaTeX but the hyperlink is to the wrong page (one lower?). Something to worry about later. @label: The label to be inserted. It must be a valid label in both LaTeX and HTML. [required] --> <template name="page" match="page[@label]"> <common formats="/latex/xelatex/"> <xsl:text>\label{</xsl:text> <xsl:value-of select="@label" /> <xsl:text>}</xsl:text> </common> <common formats="/html/xhtml/"> <a id="{@label}"></a> </common> </template> <template name="broken-page" match="page[not( @label )]"> <common> <xsl:message terminate="yes">Page elements must include a label attribute.</xsl:message> </common> </template> <!-- Figures & tables (in the LaTeX sense, i.e., "floating" items). @border-placement: The style of border to place around the figure or table. 'none' [default] 'box' or: any combination of 'top', 'left', 'bottom', 'right', e.g., 'bottom, left' (not all options may be available) --> <template name="figure" match="figure"> <common formats="/latex/xelatex/"> \begin{figure}<xsl:if test="@latex-placement">[<xsl:value-of select="@latex-placement" />]</xsl:if> \centering <xsl:choose> <xsl:when test="@border-placement = 'box'"> <xsl:text>\fbox{</xsl:text> </xsl:when> <xsl:when test="contains( @border-placement, 'top' )"> <xsl:text>\hrule\medskip</xsl:text> </xsl:when> </xsl:choose> <xsl:apply-templates select="*[not(self::caption)]" /> <xsl:choose> <xsl:when test="@border-placement = 'box'"> <xsl:text>}</xsl:text> </xsl:when> <xsl:when test="contains( @border-placement, 'bottom' )"> <xsl:text>\medskip\hrule</xsl:text> </xsl:when> </xsl:choose> <xsl:if test="count(caption) != 0"> \caption{<xsl:apply-templates select="caption" />} <xsl:if test="@label">\label{<xsl:value-of select="@label" />}</xsl:if> <xsl:if test="count(id) != 0">\label{<xsl:value-of select="id" />}</xsl:if> </xsl:if> \end{figure} </common> <common formats="/html/xhtml/"> <div class="figure" style="text-align: center; margin-top: 2em; margin-bottom: 2em;"> <div> <xsl:attribute name="style"> <xsl:if test="@border-placement = 'box'"> <xsl:text>border: 1px solid black; padding: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'top' )"> <xsl:text>border-top: 1px solid black; padding-top: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'left' )"> <xsl:text>border-left: 1px solid black; padding-left: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'bottom' )"> <xsl:text>border-bottom: 1px solid black; padding-bottom: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'right' )"> <xsl:text>border-right: 1px solid black; padding-right: 1em; </xsl:text> </xsl:if> </xsl:attribute> <xsl:if test="@label"><a id="{@label}"></a></xsl:if> <xsl:if test="count(id) != 0"><a id="{id}"></a></xsl:if> <xsl:apply-templates select="*[not(self::caption)]" /> </div> <xsl:if test="count(caption) != 0"> <br /> <xsl:apply-templates select="caption" /> </xsl:if> </div> </common> </template> <template name="table" match="table"> <common formats="/latex/xelatex/"> \begin{table}<xsl:if test="@latex-placement">[<xsl:value-of select="@latex-placement" />]</xsl:if> \centering <xsl:choose> <!-- TODO: test this with embedded tabulars. It might not work! --> <xsl:when test="@border-placement = 'box'"> <xsl:text>\fbox{</xsl:text> </xsl:when> <xsl:when test="contains( @border-placement, 'top' )"> <xsl:text>\hrule\medskip</xsl:text> </xsl:when> </xsl:choose> <xsl:apply-templates select="*[not(self::caption)]" /> <xsl:choose> <xsl:when test="@border-placement = 'box'"> <xsl:text>}</xsl:text> </xsl:when> <xsl:when test="contains( @border-placement, 'bottom' )"> <xsl:text>\medskip\hrule</xsl:text> </xsl:when> </xsl:choose> <xsl:if test="count(caption) != 0"> \caption{<xsl:apply-templates select="caption" />} <xsl:if test="@label">\label{<xsl:value-of select="@label" />}</xsl:if> </xsl:if> \end{table} </common> <common formats="/html/xhtml/"> <div class="table" style="text-align: center; margin-top: 2em; margin-bottom: 2em;"> <div> <xsl:attribute name="style"> <xsl:if test="@border-placement = 'box'"> <xsl:text>border: 1px solid black; padding: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'top' )"> <xsl:text>border-top: 1px solid black; padding-top: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'left' )"> <xsl:text>border-left: 1px solid black; padding-left: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'bottom' )"> <xsl:text>border-bottom: 1px solid black; padding-bottom: 1em; </xsl:text> </xsl:if> <xsl:if test="contains( @border-placement, 'right' )"> <xsl:text>border-right: 1px solid black; padding-right: 1em; </xsl:text> </xsl:if> </xsl:attribute> <xsl:if test="@label"><a id="{@label}"></a></xsl:if> <xsl:if test="count(id) != 0"><a id="{id}"></a></xsl:if> <xsl:apply-templates select="*[not(self::caption)]" /> </div> <xsl:if test="@label"><a id="{@label}"></a></xsl:if> <xsl:apply-templates select="*[not(self::caption)]" /> <xsl:if test="count(caption) != 0"> <br /> <xsl:apply-templates select="caption" /> </xsl:if> </div> </common> </template> <template name="multipart-table" match="table[count(part) > 0]"> <common formats="/latex/xelatex/"> <xsl:for-each select="part"> \begin{table}[p] \centering <xsl:choose> <!-- TODO: test this with embedded tabulars. It might not work! --> <xsl:when test="../@border-placement = 'box'"> <xsl:text>\fbox{</xsl:text> </xsl:when> <xsl:when test="contains( ../@border-placement, 'top' )"> <xsl:text>\hrule\medskip</xsl:text> </xsl:when> </xsl:choose> <xsl:apply-templates /> <xsl:choose> <xsl:when test="../@border-placement = 'box'"> <xsl:text>}</xsl:text> </xsl:when> <xsl:when test="contains( ../@border-placement, 'bottom' )"> <xsl:text>\medskip\hrule</xsl:text> </xsl:when> </xsl:choose> <xsl:if test="count(../caption) != 0"> <xsl:text>\caption{</xsl:text> <xsl:apply-templates select="../caption" /> <xsl:choose> <xsl:when test="position() > 1"> <xsl:text> \emph{(continued)}}</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text> \emph{(continues over)}}</xsl:text> <xsl:if test="../@label">\label{<xsl:value-of select="../@label" />}</xsl:if> </xsl:otherwise> </xsl:choose> <!-- Consider the possibility of labels for each part? --> <!-- <xsl:if test="@label">\label{<xsl:value-of select="@label" />}</xsl:if> --> </xsl:if> \end{table} \addtocounter{table}{-1} \clearpage </xsl:for-each> \stepcounter{table} </common> </template> <template name="figure-caption" match="figure/caption"> <common formats="/latex/xelatex/"><xsl:apply-templates /></common> <common formats="/html/xhtml/"> <p style="text-align: center;"> <strong> <xsl:text>Figure </xsl:text> <xsl:choose> <xsl:when test="$showanswers='yes'"> <xsl:number count="figure" level="any" format="1" /> </xsl:when> <xsl:otherwise> <xsl:number count="figure[not(ancestor::answer) and not(ancestor::omit) and not(ancestor::comment)]" level="any" format="1" /> </xsl:otherwise> </xsl:choose> <xsl:text>. </xsl:text> </strong> <xsl:apply-templates /> </p> </common> </template> <template name="table-caption" match="table/caption"> <common formats="/latex/xelatex/"><xsl:apply-templates /></common> <common formats="/html/xhtml/"> <p style="text-align: center;"> <strong> <xsl:text>Table </xsl:text> <xsl:choose> <xsl:when test="$showanswers='yes'"> <xsl:number count="table" level="any" format="1" /> </xsl:when> <xsl:otherwise> <xsl:number count="table[not(ancestor::answer) and not(ancestor::omit) and not(ancestor::comment)]" level="any" format="1" /> </xsl:otherwise> </xsl:choose> <xsl:text>. </xsl:text> </strong> <xsl:apply-templates /> </p> </common> </template> <!-- Images. Includes a scaling factor for LaTeX. To do: alternatively, allow defining the scaling factor by specifying what proportion of the page width the image should occupy (a la LaTeX [width] parameter). How about a <latex-attributes> element that can be used to specify \includegraphics arguments? <width keepaspectratio="yes">0.5\columnwidth</width> <height>2cm</height> <scale>0.5</scale> etc. To do: if no description is given, use the basename as the content of the ALT element. Ideally, I think we should be able to define two image formats (PDF, EPS, PNG, ...) when marking up an image: one for LaTeX output, another for HTML. Mind you, if the generation of the various formats from a single master is handled outside of the XSLT processing...? --> <!-- LaTeX images are always handled the same way regardless. --> <template name="latex-image" match="image" mode="latex"> <common formats="/latex/xelatex/"> <xsl:text>\includegraphics</xsl:text> <xsl:if test="count(latex-scaling) != 0"> <xsl:message terminate="no"><latex-scaling> element is deprecated in <image>; please use latex-options attribute instead.</xsl:message> <xsl:text>[scale=</xsl:text> <xsl:value-of select="latex-scaling" /> <xsl:text>]</xsl:text> </xsl:if> <!-- Adding general-purpose latex pass-through arguments for \includegraphics; this should eventually subsume the "scale"-only handler above. --> <!-- If providing multiple arguments, these should be comma-separated in the source XML, but do not need the enclosing square brackets. --> <xsl:if test="@latex-options"> <xsl:text>[</xsl:text> <xsl:value-of select="@latex-options" /> <xsl:text>]</xsl:text> </xsl:if> <xsl:text>{</xsl:text> <!-- Work out the full path specification for the file to be included = base-path + location (if specified) + basename. --> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <!-- Check whether the location attribute is included. --> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <!-- need to phase out "basename" as an element and switch to using an attribute --> <xsl:if test="count(basename) != 0"> <xsl:message terminate="no"><basename> element is deprecated in <image>; please use basename attribute instead.</xsl:message> <xsl:value-of select="basename" /> </xsl:if> <xsl:if test="@basename"> <xsl:value-of select="@basename" /> </xsl:if> <xsl:text>-print.</xsl:text> <!-- Figure out the image format. --> <xsl:choose> <xsl:when test="count(format) != 0"> <xsl:message terminate="no"><format> element is deprecated in <image>; please use format attribute instead.</xsl:message> <xsl:value-of select="format" /> </xsl:when> <xsl:when test="@format"> <xsl:value-of select="@format" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$image-format" /> </xsl:otherwise> </xsl:choose> <xsl:text>}</xsl:text> </common> </template> <template name="normal-image" match="image[count(provide-large-version) = 0]"> <common formats="/latex/xelatex/"><xsl:apply-templates select="." mode="latex" /></common> <common formats="/html/xhtml/"> <img class="padded" style="border-style: none;"> <xsl:attribute name="src"> <!-- Work out the full path specification for the file to be included = base-path + location (if specified) + basename. --> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <!-- Check whether the location attribute is included. --> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:value-of select="basename|@basename" /> <xsl:text>-web.</xsl:text> <xsl:choose> <!-- CME: oops, I'd originally used the "format" tag to identify the format used in the LaTeX version, not the HTML! --> <xsl:when test="count(format) != 0"> <xsl:message terminate="no"><format> element is deprecated in <image>; please use format attribute instead.</xsl:message> <xsl:value-of select="format" /> </xsl:when> <xsl:when test="@format"> <xsl:value-of select="@format" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$image-format" /> </xsl:otherwise> </xsl:choose> </xsl:attribute> <xsl:attribute name="alt"><xsl:apply-templates select="description" /></xsl:attribute> </img> </common> </template> <template name="zoomable-image" match="image[count(provide-large-version) != 0]"> <common formats="/latex/xelatex/"><xsl:apply-templates select="." mode="latex" /></common> <common formats="/html/xhtml/"> <a> <xsl:attribute name="href"> <!-- Work out the full path specification for the file to be included = base-path + location (if specified) + basename. --> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <!-- Check whether the location attribute is included. --> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:value-of select="basename|@basename" /> <xsl:text>-web-zoom.</xsl:text> <xsl:choose> <!-- CME: oops, I'd originally used the "format" tag to identify the format used in the LaTeX version, not the HTML! --> <xsl:when test="count(format) != 0"> <xsl:message terminate="no"><format> element is deprecated in <image>; please use format attribute instead.</xsl:message> <xsl:value-of select="format" /> </xsl:when> <xsl:when test="@format"> <xsl:value-of select="@format" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$image-format" /> </xsl:otherwise> </xsl:choose> </xsl:attribute> <img class="padded" style="border-style: none;"> <xsl:attribute name="src"> <!-- Work out the full path specification for the file to be included = base-path + location (if specified) + basename. --> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <!-- Check whether the location attribute is included. --> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:value-of select="basename|@basename" /> <xsl:text>-web.</xsl:text> <xsl:choose> <!-- CME: oops, I'd originally used the "format" tag to identify the format used in the LaTeX version, not the HTML! --> <xsl:when test="count(format) != 0"> <xsl:message terminate="no"><format> element is deprecated in <image>; please use format attribute instead.</xsl:message> <xsl:value-of select="format" /> </xsl:when> <xsl:when test="@format"> <xsl:value-of select="@format" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$image-format" /> </xsl:otherwise> </xsl:choose> </xsl:attribute> <xsl:attribute name="alt"> <xsl:apply-templates select="description" /> </xsl:attribute> </img> <br clear="right" /> <xsl:text>(Larger version)</xsl:text> </a> </common> </template> <!-- Include another XML/HTML/LaTeX document into the current one. If you don't specify @type, it assumes the type of document that you're currently generating (HTML or LaTeX). LaTeX documents are simply included using \input{...}. The old <latex-input> element is now deprecated. HTML documents are a little trickier, as there's no equivalent of \input{} in HTML, plus the XSLT processor always seems to generate a DOCTYPE when producing HTML, whether you want it or not, which means that you can only really include entire HTML documents, rather than HTML fragments (maybe you can turn this off?). The workaround currently is to embed the HTML document inside an <object>. A similar argument applies for plain text documents (such as code listings) that we want to include, but are externally generated and so can't just be embedded in the source XML. @type: The type of the document to be included. [optional] Valid values are: "xml" "html" [default for HTML] "latex" [default for LaTeX] "plain" (as in text/plain) @basename: Name of file to include (including suffix!). [required] @location: Path to file to include. Note that this gets a / appended to it. However, this shouldn't make any difference in normal usage. [optional] --> <template name="include-document" match="include-document"> <common> <!-- Work out the full path specification for the file to be included = base-path + location + basename. --> <xsl:variable name="file"> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:value-of select="@basename" /> </xsl:variable> </common> <common formats="/html/xhtml/"> <div> <xsl:attribute name="align"> <xsl:choose> <xsl:when test="@align"><xsl:value-of select="@align" /></xsl:when> <xsl:otherwise>left</xsl:otherwise> </xsl:choose> </xsl:attribute> <object data="{$file}"> <!-- Output text/html or text/plain as appropriate. --> <xsl:attribute name="type"> <xsl:text>text/</xsl:text> <xsl:choose> <xsl:when test="@type"><xsl:value-of select="@type" /></xsl:when> <xsl:otherwise><xsl:text>html</xsl:text></xsl:otherwise> </xsl:choose> </xsl:attribute> <xsl:attribute name="width"> <xsl:choose> <xsl:when test="@width"><xsl:value-of select="@width" /></xsl:when> <xsl:otherwise><xsl:text>100%</xsl:text></xsl:otherwise> </xsl:choose> </xsl:attribute> <xsl:attribute name="height"> <xsl:choose> <xsl:when test="@height"><xsl:value-of select="@height" /></xsl:when> <xsl:otherwise><xsl:text>100%</xsl:text></xsl:otherwise> </xsl:choose> </xsl:attribute> </object> </div> </common> <common formats="/latex/xelatex/"> <xsl:text>\</xsl:text> <!-- Note that input text files are currently verbatim'd in LaTeX. We may want to change this in future? --> <xsl:if test="@type = 'plain'"> <xsl:text>verbatim</xsl:text> </xsl:if> <xsl:text>input{</xsl:text> <xsl:value-of select="$file" /> <xsl:text>}</xsl:text> </common> </template> <!-- Note that including XML documents is currently problematic, as the document() function expects a valid XML document. Including XML fragments is impossible. XInclude will fix this, once it is widely supported (not yet). Best to avoid this completely for now. --> <template name="include-xml" match="include-document[@type='xml']"> <common> <xsl:variable name="file"> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:value-of select="@basename" /> </xsl:variable> <xsl:apply-templates select="document($file,/)" /> </common> </template> <!-- Environment setup. This enables you to define environment settings (e.g., required LaTeX packages, etc.). We normally explicitly call the sub-elements within this, so this template is empty to prevent unwanted stuff accidentally being included in the output. --> <template name="environment" match="environment" /> <!-- Load a LaTeX package. @options: Any arguments to the package. [optional] --> <template name="latex-package" match="latex-packages/package"> <common formats="/latex/xelatex/">\usepackage<xsl:if test="@options">[<xsl:value-of select="@options" />]</xsl:if>{<xsl:value-of select="." />}</common> </template> <!-- Execute a preamble LaTeX command. Use to set up things like counters, fonts, hyperref options, etc. --> <template name="latex-command" match="latex-commands/command"> <common formats="/latex/xelatex/"><xsl:value-of select="." /></common> </template> <!-- LaTeX hyphenation. A space-delimited list of hyphenated words. --> <template name="latex-hyphenation" match="latex-commands/hyphenation"> <common formats="/latex/xelatex/">\hyphenation{<xsl:value-of select="." />}</common> </template> <!-- Hmm, the following may be more complex than I thought... External environment files sort of stuff it up. Perhaps LaTeX document class stuff should be in attributes of the document element? --> <!-- Specify LaTeX document class and options. The master stylesheet specifies \documentclass[a4paper,12pt]{article}. Anything you specify here will override that completely, so be sure to set a4paper and 12pt if that's what you want. @options: The required document class options. [optional] --> <template name="latex-documentclass" match="latex-documentclass|documentclass"> <common formats="/latex/xelatex/">\documentclass[<xsl:value-of select="@options" />]{<xsl:value-of select="." />}</common> </template> <template name="latex-documentclass-options" match="latex-documentclass[@options]|documentclass[@options]"> <common formats="/latex/xelatex/">\documentclass[<xsl:value-of select="@options" />]{<xsl:value-of select="." />}</common> </template> <!-- Specify additional LaTeX document class options (i.e., in addition to the defaults). These should be a comma-separated list of the required options. These will be appended to the standard defaults (a4paper, 12pt). --> <template name="latex-document-options" match="latex-document-options"> <common formats="/latex/xelatex/"><xsl:apply-templates /></common> </template> <!-- Sometimes we might need to embed raw code to handle something tricky. --> <template name="raw-latex" match="raw-code[@format = 'latex']|raw-latex"> <common formats="/latex/xelatex/"><xsl:apply-templates /></common> </template> <!-- This can be a tricky if the document being processed declares any namespaces, as they generally end up attached to the first element of the raw HTML. I haven't discovered a workaround yet :(. --> <template name="raw-html" match="raw-code[@format = 'html']|raw-html"> <common formats="/html/xhtml/"><xsl:copy-of select="*" /></common> </template> <!-- Generate a LaTeX \input{} macro. --> <template name="latex-input" match="latex-input"> <common formats="/latex/xelatex/"> <xsl:message>Use of latex-input is deprecated. Please use include-document instead.</xsl:message> \input{<xsl:value-of select="." />} </common> </template> <!-- Conditional processing depending on the format. It may appear redundant to have two templates, but this is the only way to ensure that the LaTeX template is empty in the HTML style sheet, and vice versa. Note the assumption that all LaTeX format names include the string 'latex' and all HTML format names include the string 'html'. @format: the format under which this XML is to be processed. [required] --> <template name="process-when-latex" match="process-when[ contains( @format, 'latex' ) ]"> <common formats="/latex/xelatex/"><xsl:apply-templates /></common> </template> <template name="process-when-html" match="process-when[ contains( @format, 'html' ) ]"> <common formats="/html/xhtml/"><xsl:apply-templates /></common> </template> <!-- Basic maths stuff. Anything more complicated is... complicated. We should probably be using MathML, but we still have to mangle it into HTML regardless. @style: How to format the maths expression. Valid values are: 'inline' [default] display expression inline 'display' display expression in its own paragraph --> <template name="math-inline" match="math|math[@style='inline']"> <common formats="/latex/xelatex/">\(<xsl:apply-templates />\)</common> <common formats="/html/xhtml/"><xsl:apply-templates /></common> </template> <template name="math-display" match="math[@style='display']"> <common formats="/latex/xelatex/">\[<xsl:apply-templates />\]</common> <common formats="/html/xhtml/"><p style="text-align: center;"><xsl:apply-templates /></p></common> </template> <!-- Equation arrays --> <template name="equation-array" match="equation-array"> <common formats="/latex/xelatex/"> <xsl:text>\begin{eqnarray*} </xsl:text> <xsl:apply-templates /> <xsl:text>\end{eqnarray*}</xsl:text> </common> <common formats="/html/xhtml/"> <table class="equation" border="0" style="margin-left: auto; margin-right: auto;"><xsl:apply-templates /></table> </common> </template> <!-- Hmm, LaTeX uses "&" as separators: how do we know if there's another cell coming? Ah, but the LaTeX eqnarray can have no more than three columns, so there's no need to generalise. --> <template match="equation-array/row"> <common formats="/latex/xelatex/"> <xsl:apply-templates select="left" /><xsl:text disable-output-escaping="yes"> & </xsl:text><xsl:apply-templates select="middle" /><xsl:text disable-output-escaping="yes"> & </xsl:text><xsl:apply-templates select="right" /><xsl:text> \\ \\ </xsl:text> </common> <common formats="/html/xhtml/"> <tr><td align="right"><xsl:apply-templates select="left" /></td><td align="center"><xsl:apply-templates select="middle" /></td><td align="left"><xsl:apply-templates select="right" /></td></tr> </common> </template> <!-- Roman (upright) text inside math environments. \mathrm sounds like it's probably more correct, but doesn't retain spaces (which \textup does). --> <template name="math-text" match="text"> <common formats="/latex/xelatex/">\textup{<xsl:apply-templates />}</common> <common formats="/html/xhtml/"><xsl:apply-templates /></common> </template> <!-- Calligraphic letters (upper case only for LaTeX). --> <template name="calligraphic-text" match="calligraphic|cursive"> <common formats="/latex/xelatex/">\ensuremath{\mathcal{<xsl:apply-templates />}}</common> <common formats="/html/xhtml/"><font face="cursive"><xsl:apply-templates /></font></common> </template> <!-- Digit grouping separator character for large numbers. SI conventions say this should be a space (but we could make it a comma if desired). --> <template name="digit-group-separator" match="digit-group-separator|digitsep"> <common><xsl:call-template name="thin-space" /></common> </template> <!-- Mathematical super- and subscript. --> <template name="superscript-math" match="math//superscript"> <common formats="/latex/xelatex/">\ensuremath{^{<xsl:apply-templates />}}</common> <common formats="/html/xhtml/"><sup><xsl:apply-templates /></sup></common> </template> <template name="subscript-math" match="math//subscript"> <common formats="/latex/xelatex/">\ensuremath{_{<xsl:apply-templates />}}</common> <common formats="/html/xhtml/"><sub><xsl:apply-templates /></sub></common> </template> <!-- The equivalent of LaTeX's "log-like functions". @name: The name of the function. We assume the names used by LaTeX here, as they work out correct anyway. There's actually nothing to stop you using any name you like, except that it'll probably die horribly in LaTeX :) [required] --> <template name="log-like-function" match="function"> <common formats="/latex/xelatex/">\ensuremath{\<xsl:value-of select="@name" />}</common> <common formats="/html/xhtml/"><xsl:value-of select="@name" /></common> </template> <!-- Any mathematical variable names. --> <template name="math-variable" match="variable|var"> <common formats="/latex/xelatex/">\ensuremath{\mathit{<xsl:apply-templates />}}</common> <common formats="/html/xhtml/"><i><xsl:apply-templates /></i></common> </template> <!-- A displayed fraction. Is there a nicer way of doing this in HTML? --> <template name="math-fraction" match="fraction"> <common formats="/latex/xelatex/">\ensuremath{\frac{<xsl:apply-templates select="numerator" />}{<xsl:apply-templates select="denominator" />}}</common> <html> <sup><xsl:apply-templates select="numerator" /></sup> <xsl:text disable-output-escaping="yes">&frasl;</xsl:text> <sub><xsl:apply-templates select="denominator" /></sub> </html> <xhtml> <sup><xsl:apply-templates select="numerator" /></sup> <span class="unicode"> <!-- U+2044 FRACTION SLASH --> <xsl:text>⁄</xsl:text> </span> <sub><xsl:apply-templates select="denominator" /></sub> </xhtml> </template> <!-- Format a University paper code. These normally appear in the form "SPOD 123", i.e., a space between the subject code and the paper number. --> <template name="paper" match="paper"> <common> <xsl:apply-templates select="subject-code" /> <xsl:text> </xsl:text> <xsl:apply-templates select="paper-number" /> </common> </template> <template name="subject-code" match="paper/subject-code"> <common><xsl:apply-templates /></common> </template> <template name="paper-number" match="paper/paper-number"> <common><xsl:apply-templates /></common> </template> <!-- Multi-column page layouts. --> <include href="modules/multi-column.xml" /> <!-- Center stuff on the page. --> <template name="center" match="center|centering|centre|centring"> <common formats="/latex/xelatex/"> \begin{center} <xsl:apply-templates /> \end{center} </common> <common formats="/html/xhtml/"> <div style="text-align: center;"> <xsl:apply-templates /> </div> </common> </template> <!-- Bibliographies and reference lists. --> <include href="modules/bibliography.xml" /> <!-- Format numbers. --> <include href="modules/number-formatting.xml" /> </stylesheet>
Ignore Space
Show notes
View
modules/cross-references.xml
0 → 100755
<?xml version="1.0" encoding="utf-8"?> <!-- Cross-references. Note the distinction betwen these and hyperlinks: a cross-reference is merely something like "see Section 2.3", and doesn't necessarily imply a hyperlink, or vice versa. The "reference" mode templates generate the main reference text, e.g., "see Section 2.3", "see Figure 1", etc. The "page-reference" mode template generate page reference text, e.g., "on page 23". --> <stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Top level template for cross-references. There are separate templates below for each type of referenced item, as this is easier to implement. @label: The label of the item that we're referencing. It must be a valid label in both LaTeX and HTML. [required] @include-pageref: If "yes", also append a page reference (LaTeX only; this is handled by the "item-page-reference" template below). --> <template name="reference" match="reference[@label]"> <common> <!-- Find the element whose label is the same as our label. --> <xsl:apply-templates select="//*[@label = current()/@label]" mode="reference" /> <xsl:if test="@include-pageref = 'yes'"> <xsl:apply-templates select="//*[@label = current()/@label]" mode="page-reference" /> </xsl:if> </common> </template> <!-- ERROR: reference element with no label. --> <template name="broken-reference" match="reference[not( @label )]"> <common> <xsl:message terminate="yes">Reference elements must include a label attribute.</xsl:message> </common> </template> <!-- Section reference. --> <template name="section-reference" match="section" mode="reference"> <!-- It's probably more consistent to just use \ref* and insert "Section" ourselves rather than let LaTeX do it. --> <common formats="/latex/xelatex/"> <xsl:text>Section~\ref*{</xsl:text> <xsl:value-of select="@label" /> <xsl:text>}</xsl:text> </common> <common formats="/html/xhtml/"> <xsl:text disable-output-escaping="yes">Section&nbsp;</xsl:text> <xsl:number count="section" level="multiple" format="1.1.1.1.1.1" /> </common> </template> <!-- Figure reference. --> <template name="figure-reference" match="figure" mode="reference"> <common formats="/latex/xelatex/"> <xsl:text>Figure~\ref*{</xsl:text> <xsl:value-of select="@label" /> <xsl:text>}</xsl:text> </common> <common formats="/html/xhtml/"> <xsl:text disable-output-escaping="yes">Figure&nbsp;</xsl:text> <xsl:choose> <xsl:when test="$showanswers='yes'"> <xsl:number count="figure" level="any" format="1" /> </xsl:when> <xsl:otherwise> <xsl:number count="figure[not(ancestor::answer) and not(ancestor::omit) and not(ancestor::comment)]" level="any" format="1" /> </xsl:otherwise> </xsl:choose> </common> </template> <!-- Table reference. --> <template name="table-reference" match="table" mode="reference"> <common formats="/latex/xelatex/"> <xsl:text>Table~\ref*{</xsl:text> <xsl:value-of select="@label" /> <xsl:text>}</xsl:text> </common> <common formats="/html/xhtml/"> <xsl:text disable-output-escaping="yes">Table&nbsp;</xsl:text> <xsl:choose> <xsl:when test="$showanswers='yes'"> <xsl:number count="table" level="any" format="1" /> </xsl:when> <xsl:otherwise> <xsl:number count="table[not(ancestor::answer) and not(ancestor::omit) and not(ancestor::comment)]" level="any" format="1" /> </xsl:otherwise> </xsl:choose> </common> </template> <!-- Common template for item page references, as they're identical for all items. Standalone page references (i.e., not to a specific item) are dealt with below. --> <template name="item-page-reference" match="section|figure|table" mode="page-reference"> <common formats="/latex/xelatex/"> <xsl:text> on page~\pageref{</xsl:text> <xsl:value-of select="@label" /> <xsl:text>}</xsl:text> </common> </template> <!-- Generate a standalone label for use in direct page references. Any content within the element is ignored. TODO: Hmm, this seems to generate the correct page number in LaTeX but the hyperlink is to the wrong page (one lower?). Something to worry about later. @label: The label to be inserted. It must be a valid label in both LaTeX and HTML. [required] --> <template name="page" match="page[@label]"> <common formats="/latex/xelatex/"> <xsl:text>\label{</xsl:text> <xsl:value-of select="@label" /> <xsl:text>}</xsl:text> </common> <common formats="/html/xhtml/"> <a id="{@label}"></a> </common> </template> <!-- ERROR: page element with no label. --> <template name="broken-page" match="page[not( @label )]"> <common> <xsl:message terminate="yes">Page elements must include a label attribute.</xsl:message> </common> </template> <!-- Standalone direct reference to a page (i.e., not associated with some other item like a figure or table). This only really makes sense in LaTeX, as HTML doesn't have page numbers. For HTML, we fudge things by inserting the string "here", which will make sense if the reference is wrapped with a hyperlink (as they usually should be). --> <template name="direct-page-reference" match="page[@label]" mode="reference"> <common formats="/latex/xelatex/"> <xsl:text>page~\pageref{</xsl:text> <xsl:value-of select="@label" /> <xsl:text>}</xsl:text> </common> <common formats="/html/xhtml/"> <xsl:text disable-output-escaping="yes">here</xsl:text> </common> </template> </stylesheet>
Ignore Space
Show notes
View
modules/hyperlinks.xml
0 → 100755
<?xml version="1.0" encoding="utf-8"?> <!-- Hyperlinks and URLs. The content of the hyperlink element becomes the link text. All hyperlink elements have these attributes: @label: A label that the hyperlink links to. The value should be an acceptable label in both LaTeX and HTML. [optional] @url: A URL that the hyperlink links to. If no link text is provided, the URL is used as the link text. [optional] Only one of @label and @url may be specified. --> <stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Type 1: hyperlink has both a label and content (i.e., link text). --> <template name="hyperlink-label" match="hyperlink[@label and node()]"> <common formats="/latex/xelatex/">\hyperref[<xsl:value-of select="@label" />]{<xsl:apply-templates />}</common> <common formats="/html/xhtml/"><a href="#{@label}"><xsl:apply-templates /></a></common> </template> <!-- Type 2: hyperlink has both a URL and content. --> <template name="hyperlink-url" match="hyperlink[@url and node()]"> <common formats="/latex/xelatex/">\href{<xsl:value-of select="@url" />}{<xsl:apply-templates />}</common> <common formats="/html/xhtml/"><a href="{@url}"><xsl:apply-templates /></a></common> </template> <!-- Type 3: hyperlink has a URL but no content. --> <template name="empty-hyperlink-url" match="hyperlink[@url and not(node())]"> <!-- Note: not safe to use the url package here because \url{...} is fragile. --> <common formats="/latex/xelatex/">\url{<xsl:value-of select="@url" />}</common> <common formats="/html/xhtml/"><a href="{@url}"><code><xsl:value-of select="@url" /></code></a></common> </template> <!-- ERROR: hyperlink has a label but no content. --> <template name="empty-hyperlink-label" match="hyperlink[@label and not(node())]"> <common> <xsl:message terminate="yes"><hyperlink> with @label must include link text.</xsl:message> </common> </template> <!-- ERROR: hyperlink has both a label and a URL. --> <template name="hyperlink-bogus" match="hyperlink[@url and @label]" priority="2"> <common> <xsl:message terminate="yes">Cannot use both @url and @label in <hyperlink>.</xsl:message> </common> </template> <!-- Internal parameterised hyperlink templates to be called by the likes of the empty Oracle documentation elements. --> <template name="hyperlink-internal" match="hyperlink" mode="hyperlink-internal"> <common> <xsl:param name="url" /> <xsl:param name="label" /> </common> <common formats="/latex/xelatex/">\href{<xsl:value-of select="$url" />}{<xsl:apply-templates select="exsl:node-set($label)" />}</common> <common formats="/html/xhtml/"><a href="{$url}"><xsl:apply-templates select="exsl:node-set($label)" /></a></common> </template> <template name="empty-hyperlink-url-internal" match="hyperlink" mode="empty-hyperlink-internal"> <common><xsl:param name="url" /></common> <common formats="/latex/xelatex/">\url{<xsl:value-of select="$url" />}</common> <common formats="/html/xhtml/"><a href="{$url}"><code><xsl:value-of select="$url" /></code></a></common> </template> <!-- A plain URL (i.e., not necessarily a hyperlink). --> <template name="url" match="url|uri|email|e-mail|email-address|e-mail-address"> <!-- Hmm, \url{...} appears to turn the URL into a non-functional link in PDF output (probably an interaction with hyperref). Not really what we want (as the link aspect is already dealt with by the <hyperlink> templates), so we'll use \nolinkurl{...}. --> <common formats="/latex/xelatex/">\nolinkurl{<xsl:apply-templates />}</common> <common formats="/html/xhtml/"><code><xsl:apply-templates /></code></common> </template> </stylesheet>
Show line notes below