<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<xsl:output method="xml" encoding="UTF-8" indent="no" omit-xml-declaration="yes" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
	<xsl:template match="/">
		<html>
			<head>
				<title>StrongBrain</title>
				<style type="text/css">
					body {
						font: 12px/18px monospace;
						color: #333;
					}
					
					div.author {
						border: 1px solid #eee;
						background: #cca;
						padding: 30px;
					}
					
					div.article {
						border: 1px solid #ccc;
						background: #acc;
						padding: 30px;
					}
				</style>
			</head>
			<body>
				<xsl:apply-templates select="/strongbrain-article/author"/>
				<xsl:apply-templates select="/strongbrain-article/article"/>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="author">
		<div class="author">
			<strong>
				<xsl:apply-templates select="first-name[. != '']"/>
				<xsl:text> </xsl:text>
				<xsl:apply-templates select="last-name[. != '']"/>
			</strong>
			<br/>
			<em>
				<xsl:apply-templates select="blurb[. != '']" mode="author"/>
			</em>
		</div>
	</xsl:template>
	<xsl:template match="article">
		<div class="article">
			<strong style="font-size: 16px;"><xsl:apply-templates select="title[. != '']"/></strong><br/>
			<xsl:apply-templates select="subtitle[. != '']"/><br/>
			<xsl:apply-templates select="blurb[. != '']" mode="article"/><br/>
			<em><xsl:apply-templates select="date[. != '']"/></em><br/><br/>
			<xsl:apply-templates select="content[. != '']"/><br/><br/>
			<xsl:apply-templates select="license[. != '']"/>
		</div>
	</xsl:template>
	<xsl:template match="first-name">
		<xsl:value-of select="."/>
	</xsl:template>
	<xsl:template match="last-name">
		<xsl:value-of select="."/>
	</xsl:template>
	<xsl:template match="blurb" mode="author">
		<xsl:value-of select="."/>
	</xsl:template>
	<xsl:template match="title">
		<xsl:value-of select="."/>
	</xsl:template>
	<xsl:template match="subtitle">
		<xsl:value-of select="."/>
	</xsl:template>
	<xsl:template match="blurb" mode="article">
		<xsl:value-of select="."/>
	</xsl:template>
	<xsl:template match="date">
		<xsl:value-of select="."/>
	</xsl:template>
	<xsl:template match="license">
		<a href="{.}"><xsl:value-of select="."/></a>
	</xsl:template>
	<xsl:template match="content" xml:space="preserve">
		<xsl:call-template name="string-replace">
			<xsl:with-param name="string" select="translate(string(.), '&#xD;', '&#xA;')"/>
			<xsl:with-param name="from" select="'&#xA;'"/>
			<xsl:with-param name="to" select="'&lt;br/>'"/>
		</xsl:call-template>
	</xsl:template>
	<xsl:template name="string-replace" xml:space="preserve">
		<xsl:param name="string"/>
		<xsl:param name="from"/>
		<xsl:param name="to"/>
		<xsl:choose>
			<xsl:when test="contains($string,$from)">
				<xsl:if test="not(starts-with($string, $from))">
					<xsl:value-of select="substring-before($string,$from)"/>
				</xsl:if>
				<xsl:value-of select="$to" disable-output-escaping="yes"/>
				<xsl:call-template name="string-replace">
					<xsl:with-param name="string" select="substring-after($string,$from)"/>
					<xsl:with-param name="from" select="$from"/>
					<xsl:with-param name="to" select="$to"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$string"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>
