<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet 
	version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:msxml="urn:schemas-microsoft-com:xslt"
	xmlns:umbraco.library="urn:umbraco.library"
	xmlns:BlogLibrary="urn:BlogLibrary"
	exclude-result-prefixes="msxml umbraco.library BlogLibrary">


<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>
<xsl:template match="/">

<h3 id="comments"><xsl:value-of select="count($currentPage/node)"/> comment(s)  for  &#8220;<xsl:value-of select="$currentPage/@nodeName"/>&#8221;</h3> 

<ol class="commentlist">
<xsl:for-each select="$currentPage/node [@nodeTypeAlias = 'BlogPostComment' and ./data[@alias='commentReply'] = '']">
<li id="comment-{@id}">
	<xsl:if test="position() mod 2 = 0">
		<xsl:attribute name="class">alt</xsl:attribute>	
	</xsl:if>
	<p class="comment_posted_on">
		<span class="comment_date">
			<xsl:value-of select="umbraco.library:FormatDateTime(@createDate, 'd MMM')"/>
		</span> - 
		<span class="comment_time">
			<xsl:value-of select="umbraco.library:FormatDateTime(@createDate, 'h:mm')"/>	
			<xsl:variable name="commentAMPM" select="umbraco.library:FormatDateTime(@createDate, 'hh')"/>
			<xsl:if test="$commentAMPM &gt;= 12">PM</xsl:if>
			<xsl:if test="$commentAMPM &lt; 12">AM</xsl:if>
		</span>	
	</p>	
	<p class="comment_meta">
		<img class="gravatar" width="40px" height="40px" src="{BlogLibrary:getGravatar(data [@alias = 'email'], 40, '')}" alt="Gravatar for {data [@alias = 'name']}" />
		<xsl:if test="data [@alias = 'comment'] != ''">
			<a rel="external nofollow">
				<xsl:attribute name="href">
					<xsl:value-of select="data [@alias = 'website']" />
				</xsl:attribute>	
				<xsl:value-of select="data [@alias = 'name']"/>
			</a>
		</xsl:if>
		<xsl:if test="data [@alias = 'comment'] = ''">
			<cite><xsl:value-of select="data [@alias = 'name']"/> </cite>
		</xsl:if>	
	</p>	
		
	<div class="commentcontent">		
		<p><xsl:value-of select="umbraco.library:ReplaceLineBreaks(data [@alias = 'comment'])" disable-output-escaping="yes"/></p>
		<!--
		DEBUG
		<p><small>this comment is id num <xsl:value-of  select="current()/@id" /></small></p>
		<xsl:if test="string(current()/data [@alias='commentReply']) != ''">
			<p><small>this comment is in reply to id num <xsl:value-of  select="current()/data [@alias='commentReply']" /></small></p>
		</xsl:if>
		<p>
			num of replies to this ->  <xsl:value-of select="count($currentPage/child::node[string(data [@alias='commentReply']) = string(current()/@id)])" />
		</p>-->
	</div>
	<xsl:if test="count($currentPage/child::node[string(data [@alias='commentReply']) = string(current()/@id)]) &gt; 0">
		<xsl:call-template name="childComments">  
			<xsl:with-param name="parent" select="umbraco.library:GetXmlNodeById(current()/@id)"/>  
		</xsl:call-template>
	</xsl:if>	
	

</li>
</xsl:for-each>
 &#160;
</ol>
</xsl:template>

<xsl:template name="childComments">
	<xsl:param name="parent"/>
	<ol class="commentlist">
		<xsl:for-each select="$currentPage/child::node[string(data [@alias='commentReply']) = string($parent/@id)]">
		
			<li id="comment-{@id}">
				<xsl:if test="position() mod 2 = 0">
					<xsl:attribute name="class">alt</xsl:attribute>	
				</xsl:if>	
				<p class="comment_posted_on">
					<span class="comment_date">
						<xsl:value-of select="umbraco.library:FormatDateTime(@createDate, 'd MMM')"/>
					</span> - 
					<span class="comment_time">
						<xsl:value-of select="umbraco.library:FormatDateTime(@createDate, 'h:mm')"/>	
						<xsl:variable name="commentAMPM" select="umbraco.library:FormatDateTime(@createDate, 'hh')"/>
						<xsl:if test="$commentAMPM &gt;= 12">PM</xsl:if>
						<xsl:if test="$commentAMPM &lt; 12">AM</xsl:if>
					</span>	
				</p>	
				<p class="comment_meta">
					<img class="gravatar" width="40px" height="40px" src="{BlogLibrary:getGravatar(data [@alias = 'email'], 40, '')}" alt="Gravatar for {data [@alias = 'name']}" />
					<xsl:if test="data [@alias = 'comment'] != ''">
						<a rel="external nofollow">
							<xsl:attribute name="href">
								<xsl:value-of select="data [@alias = 'website']" />
							</xsl:attribute>	
							<xsl:value-of select="data [@alias = 'name']"/>
						</a>
					</xsl:if>
					<xsl:if test="data [@alias = 'comment'] = ''">
						<cite><xsl:value-of select="data [@alias = 'name']"/> </cite>
					</xsl:if>	
				</p>	
					
				<div class="commentcontent">		
					<p><xsl:value-of select="umbraco.library:ReplaceLineBreaks(data [@alias = 'comment'])" disable-output-escaping="yes"/></p>
				</div>
				<xsl:if test="count($currentPage/child::node[string(data [@alias='commentReply']) = string(current()/@id)]) &gt; 0">
					<xsl:call-template name="childComments">  
						<xsl:with-param name="parent" select="umbraco.library:GetXmlNodeById(current()/@id)"/>  
					</xsl:call-template>
				</xsl:if>	
			</li>
		</xsl:for-each>
	</ol>
</xsl:template>



</xsl:stylesheet>