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

<!--
	Emoticons of various sorts.

	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">

	<!--
		Emoticons, specifically :), :| and :(. We may be able to do more with the HTML version if we switch to Unicode?
		
		The LaTeX version requires the pifont package, which has been added to the list of standard packages in xml2xslt.xsl. It also requires Microsoft's Wingdings font (jwi) to be available.

		@type: the type of emoticon [optional]
			'sad'
			'neutral' or 'meh' :)
			'happy'	[default]
	-->
	<template name="emoticon" match="emoticon|smiley">
		<common formats="/latex/xelatex/">
			<xsl:choose>
				<xsl:when test="@type eq 'sad'">
					<xsl:text>\Pisymbol{jwi}{"4C}</xsl:text>
				</xsl:when>
				<xsl:when test="@type = ('neutral', 'meh')">
					<xsl:text>\Pisymbol{jwi}{"4B}</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>\Pisymbol{jwi}{"4A}</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</common>
		<html>
			<xsl:choose>
				<xsl:when test="@type eq 'sad'">
					<xsl:text>:(</xsl:text>
				</xsl:when>
				<xsl:when test="@type = ('neutral', 'meh')">
					<xsl:text>:|</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>:)</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</html>
		<xhtml>
			<xsl:choose>
				<xsl:when test="@type eq 'sad'">
					<!-- U+2639 WHITE FROWNING FACE -->
					<span class="unicode"><xsl:text>☹</xsl:text></span>
				</xsl:when>
				<!-- There doesn't appear to be a Unicode character for this one. :( -->
				<xsl:when test="@type = ('neutral', 'meh')">
					<xsl:text>:|</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<!-- U+263A WHITE SMILING FACE -->
					<span class="unicode"><xsl:text>☺</xsl:text></span>
				</xsl:otherwise>
			</xsl:choose>
		</xhtml>
	</template>
	
	<template name="emoticon-strip" match="emoticon|smiley" mode="strip">
		<common formats="/html/xhtml/">
			<xsl:call-template name="emoticon" />
		</common>
	</template>

</stylesheet>