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
- Added new mechanism for better handling of assignment due dates.
- Made more consistent use of xsl:text.
master
1 parent
afa0201
commit
4bf6af11c3e95291f5319d632b755670cc0a306f
nstanger
authored
on 24 Apr 2012
Patch
Showing
3 changed files
modules/global-elements.xml
modules/titling.xml
xml2xslt.xsl
Ignore Space
Show notes
View
modules/global-elements.xml
<?xml version="1.0" encoding="utf-8"?> <!-- 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). One or two are dynamic, based on elements within the document (e.g., the due date for an assignment). The "strip" mode forms of the templates are for use in the context of an HTML <title> element (so the mode is only relevant to the HTML formats). Embedding HTML markup inside the <title> element causes the markup to appear verbatim in the window title, i.e., <title><em>foo</em> bar</title> will appear in the window title as "<em>foo</em> bar", not "foo bar". Putting the stylesheet into strip mode means that it will only output text nodes unless otherwise specified for a particular element. Generally the "strip" templates will simply call-template to the original, unless the original contains markup that needs to be eliminated (e.g., see OracleServer below). The downside of this approach, of course, is that you need "strip" mode templates for quite a lot of things, but that can't really be helped. --> <stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Subject code (e.g., "INFO"). --> <template name="SubjectCode" match="SubjectCode"> <common> <xsl:value-of select="$subject-code" /> </common> </template> <template name="SubjectCode-strip" match="SubjectCode" mode="strip"> <common formats="/html/xhtml/"> <xsl:call-template name="SubjectCode" /> </common> </template> <!-- Paper number (e.g., "212"). --> <template name="PaperNumber" match="PaperNumber"> <common> <xsl:value-of select="$paper-number" /> </common> </template> <template name="PaperNumber-strip" match="PaperNumber" mode="strip"> <common formats="/html/xhtml/"> <xsl:call-template name="PaperNumber" /> </common> </template> <!-- Complete paper code (e.g., "INFO 212"). --> <template name="PaperCode" match="PaperCode"> <common> <xsl:value-of select="$subject-code" /> <xsl:text> </xsl:text> <xsl:value-of select="$paper-number" /> </common> </template> <template name="PaperCode-strip" match="PaperCode" mode="strip"> <common formats="/html/xhtml/"> <xsl:call-template name="PaperCode" /> </common> </template> <!-- Year in which the paper is offered, plus or minus some offset. @offset: Output the year +/- some integer value. The input value is truncated and defaults to zero if not supplied. --> <template name="PaperYear" match="PaperYear"> <common> <xsl:variable name="add"> <xsl:value-of select="floor(@offset)" /> <xsl:if test="not(@offset)">0</xsl:if> </xsl:variable> <xsl:value-of select="$paper-year + $add" /> </common> </template> <template name="PaperYear-strip" match="PaperYear" mode="strip"> <common formats="/html/xhtml/"> <xsl:call-template name="PaperYear" /> </common> </template> <!-- Period in which a paper is offered (e.g., "Semester 2"). --> <template name="PaperPeriod" match="PaperPeriod"> <common> <xsl:value-of select="$paper-period" /> </common> </template> <template name="PaperPeriod-strip" match="PaperPeriod" mode="strip"> <common formats="/html/xhtml/"> <xsl:call-template name="PaperPeriod" /> </common> </template> <!-- The name of the currently used Oracle server. --> <template name="OracleServer" match="OracleServer"> <common formats="/latex/xelatex/">Oracle11\textit{g}</common> <common formats="/html/xhtml/">Oracle11<i>g</i></common> </template> <template name="OracleServer-strip" match="OracleServer" mode="strip"> <common formats="/html/xhtml/"> <xsl:text>Oracle11g</xsl:text> </common> </template> <!-- The release number of the currently used Oracle server. --> <template name="OracleServerRelease" match="OracleServerRelease"> <common>1</common> </template> <template name="OracleServerRelease-strip" match="OracleServerRelease" mode="strip"> <common formats="/html/xhtml/"> <xsl:call-template name="OracleServerRelease" /> </common> </template> <!-- The version number of the currently used Oracle server. --> <template name="OracleServerVersion" match="OracleServerVersion"> <common>11.1</common> </template> <template name="OracleServerVersion-strip" match="OracleServerVersion" mode="strip"> <common formats="/html/xhtml/"> <xsl:call-template name="OracleServerVersion" /> </common> </template> <!-- A link to Blackboard. --> <template name="Blackboard" match="Blackboard"> <common> <xsl:call-template name="hyperlink-internal"> <xsl:with-param name="url">http://blackboard.otago.ac.nz/</xsl:with-param> <xsl:with-param name="label">Blackboard</xsl:with-param> </xsl:call-template> </common> </template> <template name="Blackboard-strip" match="Blackboard" mode="strip"> <common formats="/html/xhtml/"> <xsl:text>Blackboard</xsl:text> </common> </template> <!-- Assignment due date. Obviously this is only relevant if /document/@class is "assignment". The code seems a little inelegant, but there isn't really any other way to do it. @style: Additional formatting to apply to the due date when displayed. It should be a delimited list (it doesn't really matter what the delimiter is) containing one or more of the following values: "bold", "italic", "underline". Anything unrecognised is ignored. --> <template name="DueDate" match="DueDate"> <common formats="/latex/xelatex/"> <xsl:if test="contains( @style, 'bold' )"> <xsl:text>\textbf{</xsl:text> </xsl:if> <xsl:if test="contains( @style, 'italic' )"> <xsl:text>\emph{</xsl:text> </xsl:if> <xsl:if test="contains( @style, 'underline' )"> <xsl:text>\underline{</xsl:text> </xsl:if> <xsl:value-of select="/document/due-date" /> <!-- It doesn't actually matter in what order we generate the closing braces. --> <xsl:if test="contains( @style, 'underline' )"> <xsl:text>}</xsl:text> </xsl:if> <xsl:if test="contains( @style, 'italic' )"> <xsl:text>}</xsl:text> </xsl:if> <xsl:if test="contains( @style, 'bold' )"> <xsl:text>}</xsl:text> </xsl:if> </common> <common formats="/html/xhtml/"> <!-- Unfortunately, we have to generate the formatting elements as raw text rather than proper elements because otherwise the XSLT code would not be well-formed. --> <xsl:if test="contains( @style, 'bold' )"> <xsl:text disable-output-escaping="yes"><strong></xsl:text> </xsl:if> <xsl:if test="contains( @style, 'italic' )"> <xsl:text disable-output-escaping="yes"><em></xsl:text> </xsl:if> <xsl:if test="contains( @style, 'underline' )"> <xsl:text disable-output-escaping="yes"><ul></xsl:text> </xsl:if> <xsl:value-of select="/document/due-date" /> <xsl:if test="contains( @style, 'underline' )"> <!-- We must close the elements in the correct order! --> <xsl:text disable-output-escaping="yes"></ul></xsl:text> </xsl:if> <xsl:if test="contains( @style, 'italic' )"> <xsl:text disable-output-escaping="yes"></em></xsl:text> </xsl:if> <xsl:if test="contains( @style, 'bold' )"> <xsl:text disable-output-escaping="yes"></strong></xsl:text> </xsl:if> </common> </template> <!-- It seems pretty unlikely that someone will want to put the due date in the HTML document title, but I'm paranoid :). --> <template name="DueDate-strip" match="DueDate" mode="strip"> <common formats="/html/xhtml/"> <xsl:value-of select="/document/due-date" /> </common> </template> </stylesheet>
<?xml version="1.0" encoding="utf-8"?> <!-- Various "global" elements that are frequently used across all documents. Some are passed in as arguments to the stylesheet (e.g., paper number), while others are things that don't change that often, and are thus hard coded (e.g., Oracle version). The "strip" mode forms of the templates are for use in the context of an HTML <title> element (so the mode is only relevant to the HTML formats). Embedding HTML markup inside the <title> element causes the markup to appear verbatim in the window title, i.e., <title><em>foo</em> bar</title> will appear in the window title as "<em>foo</em> bar", not "foo bar". Putting the stylesheet into strip mode means that it will only output text nodes unless otherwise specified for a particular element. Generally the "strip" templates will simply call-template to the original, unless the original contains markup that needs to be eliminated (e.g., see OracleServer below). The downside of this approach, of course, is that you need "strip" mode templates for quite a lot of things, but that can't really be helped. --> <stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Subject code (e.g., "INFO"). --> <template name="SubjectCode" match="SubjectCode"> <common> <xsl:value-of select="$subject-code" /> </common> </template> <template name="SubjectCode-strip" match="SubjectCode" mode="strip"> <common formats="/html/xhtml/"> <xsl:call-template name="SubjectCode" /> </common> </template> <!-- Paper number (e.g., "212"). --> <template name="PaperNumber" match="PaperNumber"> <common> <xsl:value-of select="$paper-number" /> </common> </template> <template name="PaperNumber-strip" match="PaperNumber" mode="strip"> <common formats="/html/xhtml/"> <xsl:call-template name="PaperNumber" /> </common> </template> <!-- Complete paper code (e.g., "INFO 212"). --> <template name="PaperCode" match="PaperCode"> <common> <xsl:value-of select="$subject-code" /> <xsl:text> </xsl:text> <xsl:value-of select="$paper-number" /> </common> </template> <template name="PaperCode-strip" match="PaperCode" mode="strip"> <common formats="/html/xhtml/"> <xsl:call-template name="PaperCode" /> </common> </template> <!-- Year in which the paper is offered, plus or minus some offset. @offset: Output the year +/- some integer value. The input value is truncated and defaults to zero if not supplied. --> <template name="PaperYear" match="PaperYear"> <common> <xsl:variable name="add"> <xsl:value-of select="floor(@offset)" /> <xsl:if test="not(@offset)">0</xsl:if> </xsl:variable> <xsl:value-of select="$paper-year + $add" /> </common> </template> <template name="PaperYear-strip" match="PaperYear" mode="strip"> <common formats="/html/xhtml/"> <xsl:call-template name="PaperYear" /> </common> </template> <!-- Period in which a paper is offered (e.g., "Semester 2"). --> <template name="PaperPeriod" match="PaperPeriod"> <common> <xsl:value-of select="$paper-period" /> </common> </template> <template name="PaperPeriod-strip" match="PaperPeriod" mode="strip"> <common formats="/html/xhtml/"> <xsl:call-template name="PaperPeriod" /> </common> </template> <!-- The name of the currently used Oracle server. --> <template name="OracleServer" match="OracleServer"> <common formats="/latex/xelatex/">Oracle11\textit{g}</common> <common formats="/html/xhtml/">Oracle11<i>g</i></common> </template> <template name="OracleServer-strip" match="OracleServer" mode="strip"> <common formats="/html/xhtml/"> <xsl:text>Oracle11g</xsl:text> </common> </template> <!-- The release number of the currently used Oracle server. --> <template name="OracleServerRelease" match="OracleServerRelease"> <common>1</common> </template> <template name="OracleServerRelease-strip" match="OracleServerRelease" mode="strip"> <common formats="/html/xhtml/"> <xsl:call-template name="OracleServerRelease" /> </common> </template> <!-- The version number of the currently used Oracle server. --> <template name="OracleServerVersion" match="OracleServerVersion"> <common>11.1</common> </template> <template name="OracleServerVersion-strip" match="OracleServerVersion" mode="strip"> <common formats="/html/xhtml/"> <xsl:call-template name="OracleServerVersion" /> </common> </template> <!-- A link to Blackboard. --> <template name="Blackboard" match="Blackboard"> <common> <xsl:call-template name="hyperlink-internal"> <xsl:with-param name="url">http://blackboard.otago.ac.nz/</xsl:with-param> <xsl:with-param name="label">Blackboard</xsl:with-param> </xsl:call-template> </common> </template> <template name="Blackboard-strip" match="Blackboard" mode="strip"> <common formats="/html/xhtml/"> <xsl:text>Blackboard</xsl:text> </common> </template> </stylesheet>
Ignore Space
Show notes
View
modules/titling.xml
<?xml version="1.0" encoding="utf-8"?> <!-- Elements for generating "titling" components, such as title, author, date, in various contexts. --> <stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Items appearing in the document "preamble", i.e., the preamble section in LaTeX and the <head> element in HTML. --> <!-- Document title. --> <template name="preamble-title" match="document/title" mode="preamble"> <common formats="/latex/xelatex/"> <xsl:text>\title{</xsl:text> <!-- Note that tutorials and labs have their own special macros, which is why they're not included here (see the TODO in the "chapter-title" template below). --> <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 the HTML title, strip out any markup (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> <!-- Document author. This only makes sense for LaTeX. --> <template name="preamble-author" match="document/author" mode="preamble"> <common formats="/latex/xelatex/"> <xsl:text>\author{</xsl:text> <xsl:apply-templates /> <xsl:text>}</xsl:text> </common> </template> <!-- Document date. This only makes sense for LaTeX. --> <template name="preamble-date" match="document/date" mode="preamble"> <common formats="/latex/xelatex/"> <xsl:text>\date{</xsl:text> <xsl:apply-templates /> <xsl:text>}</xsl:text> </common> </template> <!-- Assignment due date. This only makes sense for assignments in LaTeX. --> <template name="preamble-due-date" match="document/due-date" mode="preamble"> <common formats="/latex/xelatex/"> <xsl:if test="/document/@class != 'assignment'"> <xsl:message terminate="yes">You can only use the due-date element if the document class is "assignment".</xsl:message> </xsl:if> <xsl:if test="/document/date"> <xsl:message terminate="yes">You can't include both a due-date and a date element in an assignment.</xsl:message> </xsl:if> <xsl:choose> <xsl:when test="/document/author"> <xsl:text>\date{DUE DATE: </xsl:text> <xsl:apply-templates /> <xsl:text>}</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>\author{DUE DATE: </xsl:text> <xsl:apply-templates /> <xsl:text>}</xsl:text> <xsl:text>\date{}</xsl:text> </xsl:otherwise> </xsl:choose> </common> </template> <!-- Items appearing in the document body. --> <!-- Document title. --> <template name="document-title" match="document/title"> <!-- This template is irrelevant for LaTeX, as the document title is generated by a \maketitle in the generated LaTeX markup (see xml2xslt.xsl). --> <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> <!-- Document author. --> <template name="document-author" match="document/author"> <common formats="/html/xhtml/"><p><xsl:apply-templates /></p></common> </template> <!-- Document date. --> <template name="document-date" match="document/date" /> <!-- Assignment due date. This only makes sense for assignments. --> <template name="document-due-date" match="document/due-date"> <common formats="/html/xhtml/"> <xsl:if test="/document/@class != 'assignment'"> <xsl:message terminate="yes">You can only use the due-date element if the document class is "assignment".</xsl:message> </xsl:if> <p> <xsl:text>DUE DATE: </xsl:text> <xsl:value-of select="." /> </p> </common> </template> <!-- Chapter titles 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 (coursehandbook.cls) 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 the \tutorial, etc., 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> </stylesheet>
<?xml version="1.0" encoding="utf-8"?> <!-- Elements for generating "titling" components, such as title, author, date, in various contexts. --> <stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Items appearing in the document "preamble", i.e., the preamble section in LaTeX and the <head> element in HTML. --> <!-- Document title. --> <template name="preamble-title" match="document/title" mode="preamble"> <common formats="/latex/xelatex/"> <xsl:text>\title{</xsl:text> <!-- Note that tutorials and labs have their own special macros, which is why they're not included here (see the TODO in the "chapter-title" template below). --> <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 the HTML title, strip out any markup (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> <!-- Document author. This only makes sense for LaTeX. --> <template name="preamble-author" match="document/author" mode="preamble"> <common formats="/latex/xelatex/">\author{<xsl:apply-templates />}</common> </template> <!-- Document date. This only makes sense for LaTeX. --> <template name="preamble-date" match="document/date" mode="preamble"> <common formats="/latex/xelatex/">\date{<xsl:apply-templates />}</common> </template> <!-- Items appearing in the document body. --> <!-- Document title. --> <template name="document-title" match="document/title"> <!-- This template is irrelevant for LaTeX, as the document title is generated by a \maketitle in the generated LaTeX markup (see xml2xslt.xsl). --> <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> <!-- Document author. --> <template name="document-author" match="document/author"> <common formats="/html/xhtml/"><p><xsl:apply-templates /></p></common> </template> <!-- Document date. --> <template name="document-date" match="document/date" /> <!-- Chapter titles 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 (coursehandbook.cls) 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 the \tutorial, etc., 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> </stylesheet>
Ignore Space
Show notes
View
xml2xslt.xsl
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsl-out="[irrelevant]" xmlns:exsl="http://exslt.org/common" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:infosci="http://info-nts-12.otago.ac.nz/infosci"> <!-- XSLT transformation for a master XML document defining how to transform elements in the course handbook source into HTML and LaTeX. Hmm, meta-stylesheet?! --> <!-- <xsl:output method="text" encoding="utf-8" media-type="text/xml" /> --> <xsl:output method="xml" encoding="utf-8" cdata-section-elements="html" /> <!-- What target format are we generating a styesheet for? Possible values: html, xhtml, latex (includes pdflatex), xelatex. --> <xsl:param name="target-format">html</xsl:param> <!-- Define an alias for the xsl namespace to avoid confusion when generating xsl: elements in the output of this stylesheet. --> <xsl:namespace-alias stylesheet-prefix="xsl-out" result-prefix="xsl" /> <!-- Some useful variables. (Could some of these become callable templates?) --> <xsl:variable name="newline"> <xsl:text> </xsl:text> </xsl:variable> <xsl:variable name="space"><xsl:text> </xsl:text></xsl:variable> <xsl:template match="/"> <xsl-out:stylesheet version="2.0" exclude-result-prefixes="exsl"> <xsl-out:strip-space elements="*" /> <xsl-out:param name="subject-code">INFO</xsl-out:param> <xsl-out:param name="paper-number" /> <xsl-out:param name="paper-year" /> <xsl-out:param name="paper-period" /> <xsl-out:param name="showanswers" select="'no'" /> <xsl-out:param name="base-path">.</xsl-out:param> <!-- The date and time when the document was last built. --> <xsl-out:variable name="date-built" select="current-dateTime()" /> <!-- Various items from the CVS ID string, for convenience. --> <xsl-out:variable name="cvs-id-tokens" select="tokenize( /document/@cvs-id, '\s+' )" /> <xsl-out:variable name="cvs-file" select="tokenize( $cvs-id-tokens[2], ',' )[1]" /> <xsl-out:variable name="cvs-version" select="$cvs-id-tokens[3]" /> <xsl-out:variable name="cvs-date" select="tokenize( $cvs-id-tokens[4], ',' )[1]" /> <xsl-out:variable name="cvs-time" select="tokenize( $cvs-id-tokens[5], ',' )[1]" /> <xsl-out:variable name="cvs-user" select="$cvs-id-tokens[6]" /> <!-- Include the generated Oracle documentation code. --> <xsl-out:include href="oracle-docs.xsl" /> <!-- We're going to use the text encoding in a few different places, so let's work out what it should be now. --> <xsl:variable name="text-encoding"> <xsl:choose> <xsl:when test="($target-format = 'latex') or ($target-format = 'html')"> <xsl:text>iso-8859-1</xsl:text> </xsl:when> <xsl:when test="($target-format = 'xelatex') or ($target-format = 'xhtml')"> <xsl:text>utf-8</xsl:text> </xsl:when> <xsl:otherwise> <xsl:message terminate="yes"> <xsl:text>Sorry, unknown target format: </xsl:text><xsl:value-of select="$target-format" /> </xsl:message> </xsl:otherwise> </xsl:choose> </xsl:variable> <!-- root-level documents should say what type/class of document they are (lecture, tutorial, generic, ...). Do we want to call this a class or a type? --> <!-- <xsl:variable name="doctype"><xsl:value-of select="/document/@type" /></xsl:variable> --> <!-- First, output the document preamble according to target format. This is generally different for each target format. --> <xsl:choose> <!-- The HTML formats are fairly simple: the only things that change are the doctypes, version number and text encoding. --> <xsl:when test="$target-format = 'html'"> <xsl-out:output method="html" encoding="{$text-encoding}" version="4.01" media-type="text/html" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" doctype-system="http://www.w3.org/TR/html4/loose.dtd" /> </xsl:when> <xsl:when test="$target-format = 'xhtml'"> <xsl-out:output method="xml" encoding="{$text-encoding}" byte-order-mark="no" version="1.1" media-type="text/html" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" /> </xsl:when> <!-- The LaTeX formats, however have a bunch of miscellaneous boilerplate that appears at the start of every documents, and requires more complex interleaving because of hyperref. Since we need to stuff this into a template later on, we define this using a callable template, so that we can do useful things like apply-templates within it (which wouldn't work if we just used a variable). --> <xsl:when test="$target-format = 'latex'"> <xsl-out:output method="text" encoding="{$text-encoding}" media-type="text/plain" /> <!-- Set to no if you want this to be included inside another document. Appears here because it's used in the document preamble. --> <xsl-out:param name="standalone">yes</xsl-out:param> <xsl-out:template name="latex-preamble"> <xsl-out:text> \usepackage{mathpazo} % mathpple is deprecated \usepackage[T1]{fontenc} \usepackage{textcomp} </xsl-out:text> <xsl-out:apply-templates select="environment/latex-packages" /> <xsl-out:text> % Safer to specify the hyperref options directly rather than relying on % the default hyperref.cfg, as XeLaTeX seems to ignore it :(. \usepackage[ pdftex,% pdfpagemode=UseNone,% colorlinks,% urlcolor=blue,% linkcolor=red,% breaklinks ]{hyperref} \renewcommand{\ttdefault}{blg} </xsl-out:text> </xsl-out:template> </xsl:when> <xsl:when test="$target-format = 'xelatex'"> <xsl-out:output method="text" encoding="{$text-encoding}" media-type="text/plain" /> <!-- Set to no if you want this to be included inside another document. Appears here because it's used in the document preamble. --> <xsl-out:param name="standalone">yes</xsl-out:param> <xsl-out:template name="latex-preamble"> <xsl-out:text> \usepackage[no-math]{fontspec} \usepackage{mathspec} \usepackage{xunicode} \usepackage{xltxtra} \usepackage{textcomp} % ??? </xsl-out:text> <xsl-out:apply-templates select="environment/latex-packages" /> <xsl-out:text> % Safer to specify the hyperref options directly rather than relying on % the default hyperref.cfg, as XeLaTeX seems to ignore it :(. \usepackage[ xetex,% pdfpagemode=UseNone,% colorlinks,% urlcolor=blue,% linkcolor=red,% breaklinks ]{hyperref} \defaultfontfeatures{Mapping=tex-text} \setmainfont{TeX Gyre Pagella} \setmathsfont(Digits){TeX Gyre Pagella} \setmonofont[Scale=MatchLowercase]{Letter Gothic 12 Pitch} </xsl-out:text> </xsl-out:template> </xsl:when> <!-- No need for an otherwise, as weird target formats will have already been trapped by the definition of the text-encoding variable above. --> </xsl:choose> <!-- Next, output the main document body according to target format. This is generally the same across similar target formats. --> <xsl:choose> <xsl:when test="($target-format = 'html') or ($target-format = 'xhtml')"> <!-- *** (X)HTML Output *** --> <!-- Old version: before using xsl:namespace-alias: --> <!-- <xsl-out:element name="xsl:output"> <xsl-out:attribute name="method">html</xsl-out:attribute> <xsl-out:attribute name="encoding">UTF-8</xsl-out:attribute> <xsl-out:attribute name="media-type">text/html</xsl-out:attribute> <xsl-out:attribute name="doctype-public">-//W3C//DTD HTML 4.01 Transitional//EN</xsl-out:attribute> </xsl-out:element> --> <!-- Default to PNG images for web dispay. --> <xsl-out:param name="image-format">png</xsl-out:param> <!-- Nope, includes can only appear as a child of xsl:stylesheet. --> <!-- <xsl-out:include href="xml2html-root.xsl" /> --> <xsl-out:template match="/document"> <xsl-out:comment> THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT! </xsl-out:comment> <html> <head> <xsl-out:element name="link"> <xsl-out:attribute name="rel"> <xsl-out:text>Stylesheet</xsl-out:text> </xsl-out:attribute> <xsl-out:attribute name="href"> <xsl-out:text>http://info-nts-12.otago.ac.nz/</xsl-out:text> <xsl-out:value-of select="$subject-code" /> <xsl-out:value-of select="$paper-number" /> <xsl-out:text>/db_styles.css</xsl-out:text> </xsl-out:attribute> <xsl-out:attribute name="type"> <xsl-out:text>text/css</xsl-out:text> </xsl-out:attribute> </xsl-out:element> <xsl-out:element name="meta"> <xsl-out:attribute name="http-equiv"> <xsl-out:text>Content-type</xsl-out:text> </xsl-out:attribute> <xsl-out:attribute name="content"> <xsl-out:text>text/html;charset=</xsl-out:text> <xsl:value-of select="$text-encoding" /> </xsl-out:attribute> </xsl-out:element> <title> <xsl-out:apply-templates select="title" mode="preamble" /> </title> </head> <body> <xsl-out:apply-templates /> <!-- How best to approach this - certain elements that need special handling (e.g. title, author) shouldn't be passed through here as well. --> <!-- How about we just match certain elements that we know can be handled safely, e.g. sections, paragraphs, ...? (...and their aliases?) --> <!-- Are introductions just another section, or should there be an introduction element? --> <!-- The solution is to get cleverer with our templates, e.g., multiple templates for <title> that have different match patterns (document/title, section/title). --> <!-- We also need to define an empty template for the <document-metadata> element so that its contents get ignored. --> <!-- Once these are done, we can just go apply-templates and forget about it. --> <hr /> <!-- Since HTML doesn't support footnotes as such, we instead include them as endnotes at the end of the document. --> <xsl-out:if test="count(//footnote) > 0"> <h3>Notes</h3> <xsl-out:apply-templates select="//footnote" mode="list" /> <hr /> </xsl-out:if> <xsl-out:call-template name="build-date-internal"> <xsl-out:with-param name="format">long</xsl-out:with-param> <xsl-out:with-param name="style">footer</xsl-out:with-param> </xsl-out:call-template> </body> </html> </xsl-out:template> </xsl:when> <xsl:when test="($target-format = 'latex') or ($target-format = 'xelatex')"> <!-- Set to pdf if using PDFLaTeX, otherwise eps. --> <xsl-out:param name="image-format">pdf</xsl-out:param> <!-- *** LaTeX Source Output *** --> <!-- Should this produce a LaTeX source fragment or an entire valid source document? --> <xsl-out:template match="/document"> <xsl-out:choose> <xsl-out:when test="$standalone = 'yes'"> <xsl-out:text> % THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT! \documentclass[12pt,a4paper]{article} \usepackage[margin=1in]{geometry} \usepackage{multirow} \usepackage{graphicx} \usepackage{verbatim} % needed for \verbatiminput \usepackage{relalg} % needed for join operators \usepackage{pifont} \usepackage{siunitx} % number and SI unit formatting \usepackage{listings} % nicely formatted code listings </xsl-out:text> <xsl-out:call-template name="latex-preamble" /> <xsl-out:apply-templates select="environment/latex-commands" /> <xsl-out:text> \newenvironment{answer}{\par\vspace{0.5em}\itshape}{\normalfont\vspace{1.5em}} % Listings setup. We preload the most obviously like languages to speed things % up. Other languages will still work, just not quite as quickly. \lstloadlanguages{Oracle} \lstset{basicstyle=\ttfamily,basewidth=0.5em,escapeinside={(@}{@)}, showspaces=false,showstringspaces=false} </xsl-out:text> <xsl-out:apply-templates select="title" mode="preamble" /> <xsl-out:call-template name="newline-internal" /> <xsl-out:apply-templates select="author" mode="preamble" /> <xsl-out:call-template name="newline-internal" /> <xsl-out:apply-templates select="date|due-date" mode="preamble" /> <xsl-out:call-template name="newline-internal" /> <xsl-out:text> \begin{document} \maketitle </xsl-out:text> <xsl-out:apply-templates /> <!-- If you're having problems with the build date appearing in weird or annoying locations (usually because of floating items like tables and figures), set document/@auto-latex-build-date to "no". You can then use the build-date element to insert the build date wherever you like, if necessary. This really only applies to LaTeX documents. The behaviour of HTML documents is much more predictable because they don't have elements with "minds of their own", so the build date is guaranteed to always appear at the very end. --> <xsl-out:if test="not( @auto-latex-build-date ) or ( @auto-latex-build-date != 'no' )"> <xsl-out:call-template name="build-date-internal"> <xsl-out:with-param name="format">long</xsl-out:with-param> <xsl-out:with-param name="style">footer</xsl-out:with-param> </xsl-out:call-template> </xsl-out:if> <xsl-out:text>\end{document}</xsl-out:text> </xsl-out:when> <!-- Not standalone: --> <xsl-out:otherwise> <xsl-out:apply-templates select="title" mode="chapter" /> <xsl-out:apply-templates select="*[not(self::title)]" /> <xsl-out:if test="not( @auto-latex-build-date ) or ( @auto-latex-build-date != 'no' )"> <xsl-out:call-template name="build-date-internal"> <xsl-out:with-param name="format">long</xsl-out:with-param> <xsl-out:with-param name="style">footer</xsl-out:with-param> </xsl-out:call-template> </xsl-out:if> </xsl-out:otherwise> </xsl-out:choose> </xsl-out:template> </xsl:when> <!-- No need for an otherwise, as weird formats will have already been trapped by the definition of the text-encoding variable above. --> </xsl:choose> <xsl:apply-templates /> </xsl-out:stylesheet> </xsl:template> <!-- Copy across templates according to the target format. If there's no common code for a particular format, an empty template is generated. --> <xsl:template match="template"> <xsl-out:template> <!-- Much easier to just copy all attributes across verbatim rather than copying specific named attributes, because we might want to use attributes that weren't originally anticipated. Might this be a problem in future? --> <xsl:copy-of select="@*" /> <!-- Copy across code that is common to ALL target formats. Any code not specific to a particular target format will therefore always appear FIRST in the resulting template. --> <xsl:copy-of select="common[not(@formats)]/node()" /> <!-- Copy across code that is specific to the current format. --> <xsl:copy-of select="common[contains(@formats, concat('/', $target-format, '/'))]/node()" /> <xsl:copy-of select="*[name(.) = $target-format]/node()" /> </xsl-out:template> </xsl:template> <!-- Dealing with functions is slightly more complex than templates, as functions aren't allowed to be empty. We therefore have to completely ignore function definitions that have no code for the target format. The second, more specific template will match in preference to the empty one. --> <xsl:template match="function" /> <xsl:template match="function[common[contains( @formats, concat( '/', $target-format, '/' ) )]]|function[common[not( @formats )]]"> <xsl-out:function> <!-- Much easier to just copy all attributes across verbatim rather than copying specific named attributes, because we might want to use attributes that weren't originally anticipated. Might this be a problem in future? --> <xsl:copy-of select="@*" /> <!-- Copy across code that is common to ALL target formats. Any code not specific to a particular target format will therefore always appear FIRST in the resulting template. --> <xsl:copy-of select="common[not( @formats )]/node()" /> <!-- Copy across code that is specific to the current format. --> <xsl:copy-of select="common[contains( @formats, concat( '/', $target-format, '/' ) )]/node()" /> <xsl:copy-of select="*[name( . )=$target-format]/node()" /> </xsl-out:function> </xsl:template> <!-- Include templates from a stylesheet sub-module. This enables us to modularise the master stylesheet. --> <xsl:template match="include"> <xsl:apply-templates select="document( @href )/stylesheet/*" /> </xsl:template> <!-- This template produces a template that calls another template, i.e. it implements a template alias. The generated template probably doesn't need a name, but we'll put one in anyway. --> <xsl:template match="alias"> <xsl-out:template> <xsl:attribute name="name"><xsl:value-of select="@source" /></xsl:attribute> <xsl:attribute name="match"><xsl:value-of select="@source" /></xsl:attribute> <xsl-out:call-template> <xsl:attribute name="name"><xsl:value-of select="@target" /></xsl:attribute> </xsl-out:call-template> </xsl-out:template> </xsl:template> <!-- This template produces a template for processing style-oriented markup, such as empahsis, foreign terms, and quotations. --> <!-- <xsl:template match="d"> </xsl-out:template match> --> <!-- This template produces a template for processing an element that refers to a hyperlink. --> <xsl:template match="hyperlink"> </xsl:template> </xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsl-out="[irrelevant]" xmlns:exsl="http://exslt.org/common" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:infosci="http://info-nts-12.otago.ac.nz/infosci"> <!-- XSLT transformation for a master XML document defining how to transform elements in the course handbook source into HTML and LaTeX. Hmm, meta-stylesheet?! --> <!-- <xsl:output method="text" encoding="utf-8" media-type="text/xml" /> --> <xsl:output method="xml" encoding="utf-8" cdata-section-elements="html" /> <!-- What target format are we generating a styesheet for? Possible values: html, xhtml, latex (includes pdflatex), xelatex. --> <xsl:param name="target-format">html</xsl:param> <!-- Define an alias for the xsl namespace to avoid confusion when generating xsl: elements in the output of this stylesheet. --> <xsl:namespace-alias stylesheet-prefix="xsl-out" result-prefix="xsl" /> <!-- Some useful variables. (Could some of these become callable templates?) --> <xsl:variable name="newline"> <xsl:text> </xsl:text> </xsl:variable> <xsl:variable name="space"><xsl:text> </xsl:text></xsl:variable> <xsl:template match="/"> <xsl-out:stylesheet version="2.0" exclude-result-prefixes="exsl"> <xsl-out:strip-space elements="*" /> <xsl-out:param name="subject-code">INFO</xsl-out:param> <xsl-out:param name="paper-number" /> <xsl-out:param name="paper-year" /> <xsl-out:param name="paper-period" /> <xsl-out:param name="showanswers" select="'no'" /> <xsl-out:param name="base-path">.</xsl-out:param> <!-- The date and time when the document was last built. --> <xsl-out:variable name="date-built" select="current-dateTime()" /> <!-- Various items from the CVS ID string, for convenience. --> <xsl-out:variable name="cvs-id-tokens" select="tokenize( /document/@cvs-id, '\s+' )" /> <xsl-out:variable name="cvs-file" select="tokenize( $cvs-id-tokens[2], ',' )[1]" /> <xsl-out:variable name="cvs-version" select="$cvs-id-tokens[3]" /> <xsl-out:variable name="cvs-date" select="tokenize( $cvs-id-tokens[4], ',' )[1]" /> <xsl-out:variable name="cvs-time" select="tokenize( $cvs-id-tokens[5], ',' )[1]" /> <xsl-out:variable name="cvs-user" select="$cvs-id-tokens[6]" /> <!-- Include the generated Oracle documentation code. --> <xsl-out:include href="oracle-docs.xsl" /> <!-- We're going to use the text encoding in a few different places, so let's work out what it should be now. --> <xsl:variable name="text-encoding"> <xsl:choose> <xsl:when test="($target-format = 'latex') or ($target-format = 'html')"> <xsl:text>iso-8859-1</xsl:text> </xsl:when> <xsl:when test="($target-format = 'xelatex') or ($target-format = 'xhtml')"> <xsl:text>utf-8</xsl:text> </xsl:when> <xsl:otherwise> <xsl:message terminate="yes"> <xsl:text>Sorry, unknown target format: </xsl:text><xsl:value-of select="$target-format" /> </xsl:message> </xsl:otherwise> </xsl:choose> </xsl:variable> <!-- root-level documents should say what type/class of document they are (lecture, tutorial, generic, ...). Do we want to call this a class or a type? --> <!-- <xsl:variable name="doctype"><xsl:value-of select="/document/@type" /></xsl:variable> --> <!-- First, output the document preamble according to target format. This is generally different for each target format. --> <xsl:choose> <!-- The HTML formats are fairly simple: the only things that change are the doctypes, version number and text encoding. --> <xsl:when test="$target-format = 'html'"> <xsl-out:output method="html" encoding="{$text-encoding}" version="4.01" media-type="text/html" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" doctype-system="http://www.w3.org/TR/html4/loose.dtd" /> </xsl:when> <xsl:when test="$target-format = 'xhtml'"> <xsl-out:output method="xml" encoding="{$text-encoding}" byte-order-mark="no" version="1.1" media-type="text/html" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" /> </xsl:when> <!-- The LaTeX formats, however have a bunch of miscellaneous boilerplate that appears at the start of every documents, and requires more complex interleaving because of hyperref. Since we need to stuff this into a template later on, we define this using a callable template, so that we can do useful things like apply-templates within it (which wouldn't work if we just used a variable). --> <xsl:when test="$target-format = 'latex'"> <xsl-out:output method="text" encoding="{$text-encoding}" media-type="text/plain" /> <!-- Set to no if you want this to be included inside another document. Appears here because it's used in the document preamble. --> <xsl-out:param name="standalone">yes</xsl-out:param> <xsl-out:template name="latex-preamble"> <xsl-out:text> \usepackage{mathpazo} % mathpple is deprecated \usepackage[T1]{fontenc} \usepackage{textcomp} </xsl-out:text> <xsl-out:apply-templates select="environment/latex-packages" /> <xsl-out:text> % Safer to specify the hyperref options directly rather than relying on % the default hyperref.cfg, as XeLaTeX seems to ignore it :(. \usepackage[ pdftex,% pdfpagemode=UseNone,% colorlinks,% urlcolor=blue,% linkcolor=red,% breaklinks ]{hyperref} \renewcommand{\ttdefault}{blg} </xsl-out:text> </xsl-out:template> </xsl:when> <xsl:when test="$target-format = 'xelatex'"> <xsl-out:output method="text" encoding="{$text-encoding}" media-type="text/plain" /> <!-- Set to no if you want this to be included inside another document. Appears here because it's used in the document preamble. --> <xsl-out:param name="standalone">yes</xsl-out:param> <xsl-out:template name="latex-preamble"> <xsl-out:text> \usepackage[no-math]{fontspec} \usepackage{mathspec} \usepackage{xunicode} \usepackage{xltxtra} \usepackage{textcomp} % ??? </xsl-out:text> <xsl-out:apply-templates select="environment/latex-packages" /> <xsl-out:text> % Safer to specify the hyperref options directly rather than relying on % the default hyperref.cfg, as XeLaTeX seems to ignore it :(. \usepackage[ xetex,% pdfpagemode=UseNone,% colorlinks,% urlcolor=blue,% linkcolor=red,% breaklinks ]{hyperref} \defaultfontfeatures{Mapping=tex-text} \setmainfont{TeX Gyre Pagella} \setmathsfont(Digits){TeX Gyre Pagella} \setmonofont[Scale=MatchLowercase]{Letter Gothic 12 Pitch} </xsl-out:text> </xsl-out:template> </xsl:when> <!-- No need for an otherwise, as weird target formats will have already been trapped by the definition of the text-encoding variable above. --> </xsl:choose> <!-- Next, output the main document body according to target format. This is generally the same across similar target formats. --> <xsl:choose> <xsl:when test="($target-format = 'html') or ($target-format = 'xhtml')"> <!-- *** (X)HTML Output *** --> <!-- Old version: before using xsl:namespace-alias: --> <!-- <xsl-out:element name="xsl:output"> <xsl-out:attribute name="method">html</xsl-out:attribute> <xsl-out:attribute name="encoding">UTF-8</xsl-out:attribute> <xsl-out:attribute name="media-type">text/html</xsl-out:attribute> <xsl-out:attribute name="doctype-public">-//W3C//DTD HTML 4.01 Transitional//EN</xsl-out:attribute> </xsl-out:element> --> <!-- Default to PNG images for web dispay. --> <xsl-out:param name="image-format">png</xsl-out:param> <!-- Nope, includes can only appear as a child of xsl:stylesheet. --> <!-- <xsl-out:include href="xml2html-root.xsl" /> --> <xsl-out:template match="/document"> <xsl-out:comment> THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT! </xsl-out:comment> <html> <head> <xsl-out:element name="link"> <xsl-out:attribute name="rel"> <xsl-out:text>Stylesheet</xsl-out:text> </xsl-out:attribute> <xsl-out:attribute name="href"> <xsl-out:text>http://info-nts-12.otago.ac.nz/</xsl-out:text> <xsl-out:value-of select="$subject-code" /> <xsl-out:value-of select="$paper-number" /> <xsl-out:text>/db_styles.css</xsl-out:text> </xsl-out:attribute> <xsl-out:attribute name="type"> <xsl-out:text>text/css</xsl-out:text> </xsl-out:attribute> </xsl-out:element> <xsl-out:element name="meta"> <xsl-out:attribute name="http-equiv"> <xsl-out:text>Content-type</xsl-out:text> </xsl-out:attribute> <xsl-out:attribute name="content"> <xsl-out:text>text/html;charset=</xsl-out:text> <xsl:value-of select="$text-encoding" /> </xsl-out:attribute> </xsl-out:element> <title> <xsl-out:apply-templates select="title" mode="preamble" /> </title> </head> <body> <xsl-out:apply-templates /> <!-- How best to approach this - certain elements that need special handling (e.g. title, author) shouldn't be passed through here as well. --> <!-- How about we just match certain elements that we know can be handled safely, e.g. sections, paragraphs, ...? (...and their aliases?) --> <!-- Are introductions just another section, or should there be an introduction element? --> <!-- The solution is to get cleverer with our templates, e.g., multiple templates for <title> that have different match patterns (document/title, section/title). --> <!-- We also need to define an empty template for the <document-metadata> element so that its contents get ignored. --> <!-- Once these are done, we can just go apply-templates and forget about it. --> <hr /> <!-- Since HTML doesn't support footnotes as such, we instead include them as endnotes at the end of the document. --> <xsl-out:if test="count(//footnote) > 0"> <h3>Notes</h3> <xsl-out:apply-templates select="//footnote" mode="list" /> <hr /> </xsl-out:if> <xsl-out:call-template name="build-date-internal"> <xsl-out:with-param name="format">long</xsl-out:with-param> <xsl-out:with-param name="style">footer</xsl-out:with-param> </xsl-out:call-template> </body> </html> </xsl-out:template> </xsl:when> <xsl:when test="($target-format = 'latex') or ($target-format = 'xelatex')"> <!-- Set to pdf if using PDFLaTeX, otherwise eps. --> <xsl-out:param name="image-format">pdf</xsl-out:param> <!-- *** LaTeX Source Output *** --> <!-- Should this produce a LaTeX source fragment or an entire valid source document? --> <xsl-out:template match="/document"> <xsl-out:choose> <xsl-out:when test="$standalone = 'yes'"> <xsl-out:text> % THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT! \documentclass[12pt,a4paper]{article} \usepackage[margin=1in]{geometry} \usepackage{multirow} \usepackage{graphicx} \usepackage{verbatim} % needed for \verbatiminput \usepackage{relalg} % needed for join operators \usepackage{pifont} \usepackage{siunitx} % number and SI unit formatting \usepackage{listings} % nicely formatted code listings </xsl-out:text> <xsl-out:call-template name="latex-preamble" /> <xsl-out:apply-templates select="environment/latex-commands" /> <xsl-out:text> \newenvironment{answer}{\par\vspace{0.5em}\itshape}{\normalfont\vspace{1.5em}} % Listings setup. We preload the most obviously like languages to speed things % up. Other languages will still work, just not quite as quickly. \lstloadlanguages{Oracle} \lstset{basicstyle=\ttfamily,basewidth=0.5em,escapeinside={(@}{@)}, showspaces=false,showstringspaces=false} </xsl-out:text> <xsl-out:apply-templates select="title" mode="preamble" /> <xsl-out:call-template name="newline-internal" /> <xsl-out:apply-templates select="author" mode="preamble" /> <xsl-out:call-template name="newline-internal" /> <xsl-out:apply-templates select="date" mode="preamble" /> <xsl-out:call-template name="newline-internal" /> <xsl-out:text> \begin{document} \maketitle </xsl-out:text> <xsl-out:apply-templates /> <!-- If you're having problems with the build date appearing in weird or annoying locations (usually because of floating items like tables and figures), set document/@auto-latex-build-date to "no". You can then use the build-date element to insert the build date wherever you like, if necessary. This really only applies to LaTeX documents. The behaviour of HTML documents is much more predictable because they don't have elements with "minds of their own", so the build date is guaranteed to always appear at the very end. --> <xsl-out:if test="not( @auto-latex-build-date ) or ( @auto-latex-build-date != 'no' )"> <xsl-out:call-template name="build-date-internal"> <xsl-out:with-param name="format">long</xsl-out:with-param> <xsl-out:with-param name="style">footer</xsl-out:with-param> </xsl-out:call-template> </xsl-out:if> <xsl-out:text>\end{document}</xsl-out:text> </xsl-out:when> <!-- Not standalone: --> <xsl-out:otherwise> <xsl-out:apply-templates select="title" mode="chapter" /> <xsl-out:apply-templates select="*[not(self::title)]" /> <xsl-out:if test="not( @auto-latex-build-date ) or ( @auto-latex-build-date != 'no' )"> <xsl-out:call-template name="build-date-internal"> <xsl-out:with-param name="format">long</xsl-out:with-param> <xsl-out:with-param name="style">footer</xsl-out:with-param> </xsl-out:call-template> </xsl-out:if> </xsl-out:otherwise> </xsl-out:choose> </xsl-out:template> </xsl:when> <!-- No need for an otherwise, as weird formats will have already been trapped by the definition of the text-encoding variable above. --> </xsl:choose> <xsl:apply-templates /> </xsl-out:stylesheet> </xsl:template> <!-- Copy across templates according to the target format. If there's no common code for a particular format, an empty template is generated. --> <xsl:template match="template"> <xsl-out:template> <!-- Much easier to just copy all attributes across verbatim rather than copying specific named attributes, because we might want to use attributes that weren't originally anticipated. Might this be a problem in future? --> <xsl:copy-of select="@*" /> <!-- Copy across code that is common to ALL target formats. Any code not specific to a particular target format will therefore always appear FIRST in the resulting template. --> <xsl:copy-of select="common[not(@formats)]/node()" /> <!-- Copy across code that is specific to the current format. --> <xsl:copy-of select="common[contains(@formats, concat('/', $target-format, '/'))]/node()" /> <xsl:copy-of select="*[name(.)=$target-format]/node()" /> </xsl-out:template> </xsl:template> <!-- Dealing with functions is slightly more complex than templates, as functions aren't allowed to be empty. We therefore have to completely ignore function definitions that have no code for the target format. The second, more specific template will match in preference to the empty one. --> <xsl:template match="function" /> <xsl:template match="function[common[contains( @formats, concat( '/', $target-format, '/' ) )]]|function[common[not( @formats )]]"> <xsl-out:function> <!-- Much easier to just copy all attributes across verbatim rather than copying specific named attributes, because we might want to use attributes that weren't originally anticipated. Might this be a problem in future? --> <xsl:copy-of select="@*" /> <!-- Copy across code that is common to ALL target formats. Any code not specific to a particular target format will therefore always appear FIRST in the resulting template. --> <xsl:copy-of select="common[not( @formats )]/node()" /> <!-- Copy across code that is specific to the current format. --> <xsl:copy-of select="common[contains( @formats, concat( '/', $target-format, '/' ) )]/node()" /> <xsl:copy-of select="*[name( . )=$target-format]/node()" /> </xsl-out:function> </xsl:template> <!-- Include templates from a stylesheet sub-module. This enables us to modularise the master stylesheet. --> <xsl:template match="include"> <xsl:apply-templates select="document( @href )/stylesheet/*" /> </xsl:template> <!-- This template produces a template that calls another template, i.e. it implements a template alias. The generated template probably doesn't need a name, but we'll put one in anyway. --> <xsl:template match="alias"> <xsl-out:template> <xsl:attribute name="name"><xsl:value-of select="@source" /></xsl:attribute> <xsl:attribute name="match"><xsl:value-of select="@source" /></xsl:attribute> <xsl-out:call-template> <xsl:attribute name="name"><xsl:value-of select="@target" /></xsl:attribute> </xsl-out:call-template> </xsl-out:template> </xsl:template> <!-- This template produces a template for processing style-oriented markup, such as empahsis, foreign terms, and quotations. --> <!-- <xsl:template match="d"> </xsl-out:template match> --> <!-- This template produces a template for processing an element that refers to a hyperlink. --> <xsl:template match="hyperlink"> </xsl:template> </xsl:stylesheet>
Show line notes below