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

<!--
	Special characters, such as whitespace, non-printing, etc.
	
	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 space 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">

	<!--
		Insert a space. Useful for the occasional case where two elements occur next to each other with only a space separating them (e.g., an <emph> immediately following a <quote>), and the space gets gobbled by XSLT, producing non-separated words in the output. It doesn't seem very consistent as to when it does and doesn't happen, unfortunately, but when it does happen, inserting a <space /> will fix the problem.
		
		This is analogous to putting a \ at the end of macros in LaTeX to ensure that spaces after the macro aren't gobbled, and indeed, this is exactly what the LaTeX version of the markup produces.
	-->
	<template name="space" match="space">
		<common formats="/latex/xelatex/"><xsl:text>\ </xsl:text></common>
		<!-- U+0020 SPACE -->
		<common formats="/html/xhtml/"><xsl:text> </xsl:text></common>
	</template>

	<template name="space-strip" match="space" mode="strip">
		<common formats="/html/xhtml/">
			<xsl:call-template name="space" />
		</common>
	</template>
	
	
	<!-- Non-breaking space. -->

	<template name="non-breaking-space" match="non-breaking-space|nbsp|no-break-space">
		<common formats="/latex/xelatex/"><xsl:text>~</xsl:text></common>
		<common formats="/html/xhtml/"><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></common>
		<!-- Could use U+00A0 NO-BREAK SPACE for XHTML? -->
	</template>
	
	
	<!-- Thin space. -->

	<template name="thin-space" match="thin-space|thinspace">
		<common formats="/latex/xelatex/"><xsl:text>\,</xsl:text></common>
		<common formats="/html/xhtml/"><xsl:text disable-output-escaping="yes">&amp;thinsp;</xsl:text></common>
		<!-- Could use U+2009 THIN SPACE for XHTML? -->
	</template>
	
	
	<!--
		Insert a discretionary hyphen. Only relevant for LaTeX output.
	-->
	<template name="discretionary-hyphen" match="hyphen">
		<common formats="/latex/xelatex/"><xsl:text>\-</xsl:text></common>
		<!-- Could use U+00AD SOFT HYPHEN for XHTML? -->
	</template>
	

</stylesheet>