Newer
Older
XML / modules / quotations.xml
<?xml version="1.0" encoding="utf-8"?>

<!--
	Quoted text of all sorts.
-->

<stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<!--
		Inline quoted text. Handles nested quotes correctly.
		
		@single: Whether to enclose the text in single or double quotes.
			'yes' => single quotes ('').
			otherwise => double quotes (""). [default]
	-->
	<template name="single-quote" match="quote[@single='yes']|q[@single='yes']">
		<common formats="/latex/xelatex/">
			<xsl:text>`</xsl:text>
			<xsl:apply-templates />
			<xsl:text>'</xsl:text>
		</common>
		<html>
			<xsl:text disable-output-escaping="yes">&amp;lsquo;</xsl:text>
			<xsl:apply-templates />
			<xsl:text disable-output-escaping="yes">&amp;rsquo;</xsl:text>
		</html>
		<xhtml>
			<!-- U+2018 LEFT SINGLE QUOTATION MARK -->
			<xsl:text>‘</xsl:text>
			<xsl:apply-templates />
			<!-- U+2019 RIGHT SINGLE QUOTATION MARK -->
			<xsl:text>’</xsl:text>
		</xhtml>
	</template>
	
	<template name="double-quote" match="quote|qq">
		<common formats="/latex/xelatex/">
			<xsl:text>``</xsl:text>
			<xsl:apply-templates />
			<xsl:text>''</xsl:text>
		</common>
		<html>
			<xsl:text disable-output-escaping="yes">&amp;ldquo;</xsl:text>
			<xsl:apply-templates />
			<xsl:text disable-output-escaping="yes">&amp;rdquo;</xsl:text>
		</html>
		<xhtml>
			<!-- U+201C LEFT DOUBLE QUOTATION MARK -->
			<xsl:text>“</xsl:text>
			<xsl:apply-templates />
			<!-- U+201D RIGHT DOUBLE QUOTATION MARK -->
			<xsl:text>”</xsl:text>
		</xhtml>
	</template>
	
	
	<!--
		With nested quotes, we need to figure out what depth of nesting we're at, then call the appropriate template depending on the initial quoting style (single or double).
	-->
	<template name="nested-double-quote" match="quote//quote">
		<common>
			<xsl:choose>
				<xsl:when test="(count(ancestor::quote) mod 2) eq 0">
					<xsl:call-template name="double-quote" />
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="single-quote" />
				</xsl:otherwise>
			</xsl:choose>
		</common>
	</template>
	
	<template name="nested-single-quote" match="quote[@single='yes']//quote" priority="2">
		<common>
			<xsl:choose>
				<xsl:when test="(count(ancestor::quote) mod 2) eq 0">
					<xsl:call-template name="single-quote" />
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="double-quote" />
				</xsl:otherwise>
			</xsl:choose>
		</common>
	</template>


	<!--
		A block quotation. If you want quote marks, insert them using <quote> above.
		
		@align: The alignment of the quotation paragraph.
			'left' [default]
			'center' | 'centre'
			'right'
	-->
	<template name="quotation" match="quotation">
		<common formats="/latex/xelatex/">
			<xsl:choose>
				<xsl:when test="@align = ('left', 'right')">
					<xsl:text>\begin{flush</xsl:text>
					<xsl:value-of select="@align" />
					<xsl:text>}\itshape </xsl:text>
					<xsl:apply-templates />
					<xsl:text>\end{flush</xsl:text>
					<xsl:value-of select="@align" />
					<xsl:text>}</xsl:text>
				</xsl:when>
				<xsl:when test="@align = ('center', 'centre')">
					<xsl:text>\begin{center}\itshape </xsl:text>
					<xsl:apply-templates />
					<xsl:text>\end{center}</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>\begin{quote}\itshape </xsl:text>
					<xsl:apply-templates />
					<xsl:text>\end{quote}</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</common>
		<!-- Nominally we should use <blockquote>, but it doesn't have alignment. -->
		<common formats="/html/xhtml/">
			<p>
				<xsl:if test="@align">
					<xsl:attribute name="align">
						<xsl:value-of select="@align" />
					</xsl:attribute>
				</xsl:if>
				<i><xsl:apply-templates /></i>
			</p>
		</common>
	</template>

</stylesheet>