<?xml version="1.0" encoding="ISO-8859-1"?>

<!--
	Templates for my custom markup language.
	
	See: http://boodebr.org/series/myoml for a full description.
-->

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- The <article> tag -->
<xsl:template match="article">
	<html>
		<head>		
			<link href="style.css" rel="stylesheet" type="text/css" />
			<!-- Put article title in <title> element as well -->
			<title><xsl:value-of select="@series" />: <xsl:value-of select="@title" /></title>			
		</head>

		<body>
			<div class="article-container">
				<!-- Show a standard header -->
				<div class="article-header">
					<a class="hide">
						<xsl:attribute name="href">
							<xsl:value-of select="@series-url" />
						</xsl:attribute>				
						<xsl:value-of select="@series" />
					</a>: <xsl:value-of select="@title" />					
				</div>
				
				<!-- Apply templates to article content -->
				<xsl:apply-templates />
				
				<!-- Show a standard footer -->
				<div class="footer">
					<xsl:value-of select="@footer-text" />
					&#160;
					<a>
						<xsl:attribute name="href">
							<xsl:value-of select="@series-url" />
						</xsl:attribute>				
						<xsl:value-of select="@series-url-desc" />
					</a>
				</div>		
			</div>
			
		</body>
	</html>
</xsl:template>

<!-- The <section> tag -->
<xsl:template match="section">

	<div class="section">

		<xsl:choose>
			<!-- Use title=, if given -->
			<xsl:when test="string-length(@title)">
				<div class="section-title"><xsl:value-of select="@title"/></div>
			</xsl:when>
			<xsl:otherwise>
				<!-- If no title, make empty title so I still get the border -->
				<div class="section-title"></div>
			</xsl:otherwise>
		</xsl:choose>
		
		<xsl:apply-templates />
	</div>
	
</xsl:template>

<!-- <text> container -->
<xsl:template match="text">
	<div class="text">
		<xsl:apply-templates />
	</div>
</xsl:template>

<!-- <note> container -->
<xsl:template match="note">
	<div class="note-container">
		<div class="note-title">	
		<!-- use title= if user gave it, else use "NOTE" -->
		<xsl:choose>
			<xsl:when test="string-length(@title)">
				<xsl:value-of select="@title" />
			</xsl:when>
			<xsl:otherwise>NOTE</xsl:otherwise>
		</xsl:choose>
		</div>
		
		<div class="note-content">
			<xsl:apply-templates />	
		</div>
		
	</div>

</xsl:template>

<!-- <warn> container -->
<xsl:template match="warn">
	<div class="warn-container">
		<div class="warn-title">	
		<!-- use title= if user gave it, else use "WARNING" -->
		<xsl:choose>
			<xsl:when test="string-length(@title)">
				<xsl:value-of select="@title" />
			</xsl:when>
			<xsl:otherwise>WARNING</xsl:otherwise>
		</xsl:choose>
		</div>
		
		<div class="warn-content">
			<xsl:apply-templates />	
		</div>
		
	</div>

</xsl:template>

<!-- <code> container -->
<xsl:template match="code">

	<!-- Put title+content in a parent container -->
	<div class="code-container">
		<!-- Add title, if user provided one -->
		<xsl:if test="string-length(@title)">
			<div class="code-title">
				<xsl:value-of select="@title" />
			</div>
		</xsl:if>	   

		<!-- Include code as preformatted block -->
		<div class="code-content">
			<!-- ugh - substring() hack is to remove leading \n at start
				of code block. Without this hack, it looks okay when
				run through xsltproc, but has a gap when viewing the XML
				directly in Firefox.
			-->
			<pre><xsl:value-of select="substring(.,2)" /></pre></div>		
			
	</div>
</xsl:template>

<!-- <c>, for inline code samples -->
<xsl:template match="c">
	<span class="inline-code">
		<xsl:value-of select="." />
	</span>
</xsl:template>

<!-- Pass along a number of standard HTML tags as-is -->
<xsl:template match="p|i|b|tt|ul|ol|li|tr|th|td">
	<xsl:copy>
		<xsl:apply-templates />
	</xsl:copy>
</xsl:template>

<!-- There is a shorter way to do this, by using the 'use-attribute-sets'
	 parameter to <xsl:copy>, but Firefox seems to have a bug in its XSLT
	 processor, so I do it manually ... -->
<xsl:template match="a">
	<a>
		<xsl:attribute name="href">
			<xsl:value-of select="@href" />
		</xsl:attribute>
		
		<xsl:apply-templates />
	</a>
</xsl:template>

<!-- images - by default, I want to center them horizontally -->
<xsl:template match="img">
	<!-- Trick for centering images by placing them in a container.
	     From: http://www.netmechanic.com/news/vol7/html_no10.htm -->
	<div class="image-container">
		<img>
			<xsl:attribute name="src"><xsl:value-of select="@src" />
			</xsl:attribute>
		</img>
		<!-- add title= if one is given -->
		<xsl:if test="string-length(@title)">
			<div class="image-title">
				<xsl:value-of select="@title" />
			</div>
		</xsl:if>	   
	</div>	
</xsl:template>

<!-- <code> container inside of a <warn> or <note> gets 
     different styling to make it look better in those containers -->
<xsl:template match="warn//code|note//code">

	<!-- Put title+content in a parent container -->
	<div class="inner-code-container">
		<!-- Add title, if user provided one -->
		<xsl:if test="string-length(@title)">
			<div class="inner-code-title">
				<xsl:value-of select="@title" />
			</div>
		</xsl:if>	   

		<!-- Include code as preformatted block -->
		<div class="inner-code-content">
			<!-- ugh - substring() hack is to remove leading \n at start
				of code block. Without this hack, it looks okay when
				run through xsltproc, but has a gap when viewing the XML
				directly in Firefox.
			-->
			<pre><xsl:value-of select="substring(.,2)" /></pre></div>		
			
	</div>
</xsl:template>

<!-- Basically the same as an HTML table, but the title is
	 given as the title= attribute -->
<xsl:template match="table">
	<!-- Place inside outer container, as done with <code>, etc. -->
	<div class="table-container">
		<!-- use label= if user gave it. I like using a <div> instead of
			 relying on the CAPTION tag working the way I expect -->
		<xsl:if test="string-length(@title)">
			<div class="table-title">	
				<xsl:value-of select="@title" />
			</div>		
		</xsl:if>
		
		<!-- Table is built with <tr>, <th>, <td> as usual ... -->
		<table class="table-body"><xsl:apply-templates /></table>
	</div>
</xsl:template>
	 
</xsl:stylesheet>



