<xsl:stylesheet version="1.0"
	xmlns:date="http://exslt.org/dates-and-times" 
  xmlns:ebe="http://cks/ebemethods"
	xmlns:string="http://exslt.org/strings"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  exclude-result-prefixes="date ebe string">

	<xsl:param name="IsBlogOwner" />
	<xsl:param name="RelativeUrl" />
	<xsl:param name="QSpageindex" />
	<xsl:param name="TrimPostBodyOnLists"/>

	<xsl:output omit-xml-declaration="yes" />

	<xsl:template match="/">

		<xsl:variable name="endPos" select="number($QSpageindex) * 10"/>

		<xsl:choose>
			<!-- Are there any posts -->
			<xsl:when test="count(rows/row) = 0">
        <xsl:value-of select="ebe:res('NoPostInCategory')"/>
			</xsl:when>
			<!-- Is there a Query String for the page index -->
			<xsl:when test="$QSpageindex">
				<xsl:apply-templates select="rows/row[position() &gt; number($endPos)-10 and position() &lt; number($endPos)+1]"/>
			</xsl:when>
			<!-- Nope...just show the first 10 -->
			<xsl:otherwise>
				<xsl:apply-templates select="rows/row[position() &lt; 11]"/>
			</xsl:otherwise>
		</xsl:choose>

		<xsl:variable name="pos">
			<xsl:choose>
				<xsl:when test="not($QSpageindex)">1</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="number($QSpageindex)"/>
				</xsl:otherwise>
			</xsl:choose>

		</xsl:variable>

		<xsl:if test="number($endPos) &gt; 10">
			<!-- We are on another page...show the previous -->
			<a>
				<xsl:attribute name="href">
					?PageIndex=<xsl:value-of select="number($pos)-1"/>
				</xsl:attribute>
				&lt;&lt; <xsl:value-of select="ebe:res('Previous')"/> &#160;
			</a>
		</xsl:if>

		<xsl:if test="(not($QSpageindex) and count(rows/row) &gt; 10) or (($endPos) and number($endPos) &lt; count(rows/row))">
			<!-- There appear to be more posts...show a 'next' link -->
			<a>
				<xsl:attribute name="href">
					?PageIndex=<xsl:value-of select="number($pos)+1"/>
				</xsl:attribute>
				&#160;<xsl:value-of select="ebe:res('Next')"/> &gt;&gt;
			</a>
		</xsl:if>


	</xsl:template>

	<xsl:template match="row">

		<xsl:variable name="publishedDate" select="date:parseDate(PublishedDate, 'yyyy-MM-dd HH:mm:ss')" />

		<div class="content">
			<h2>
				<a title="{Title}" href="{ebe:createPostUrl(PublishedDate, BlogTitleForUrl)}">
					<xsl:value-of select="Title"/>
				</a>
			</h2>

		<div class="blogcontent">
			<xsl:if test="$IsBlogOwner = 'True'">
				<a href="/{substring-after(FileDirRef,'#')}/EditPost.aspx?ID={ID}">
          [<xsl:value-of select="ebe:res('EditPost')"/>]
				</a>
			</xsl:if>

			<div class="entry">

				<xsl:variable name="pureText">
					<xsl:call-template name="removeHtmlTags">
						<xsl:with-param name="html" select="Body" />
					</xsl:call-template>
				</xsl:variable>

				<xsl:choose>
					<xsl:when test="$TrimPostBodyOnLists = 'True'" >
						<xsl:value-of select="substring($pureText, 0, 250)" disable-output-escaping="yes" /> ...<span class="small"><a href="{ebe:createPostUrl(PublishedDate, BlogTitleForUrl)}">[<xsl:value-of select="ebe:res('ReadMore')"/>]</a></span>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="Body" disable-output-escaping="yes"/>
					</xsl:otherwise>
				</xsl:choose>

				<div class="clear"><br/>
				<div class="small">
          <xsl:value-of select="ebe:res('Published')"/>: <xsl:value-of select="date:format-date($publishedDate, 'MMM-dd-yy')"/> |
				
					<a href="{ebe:createPostUrl(PublishedDate, BlogTitleForUrl)}">
            <xsl:value-of select="NumComments"/>&#160;
            <xsl:choose>
              <xsl:when test="NumComments &gt; 1">
                <xsl:value-of select="ebe:res('Comments')"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="ebe:res('Comment')"/>
              </xsl:otherwise>
            </xsl:choose>
					</a>
					|
					<a href="{ebe:createPostUrl(PublishedDate, BlogTitleForUrl)}">
						<xsl:value-of select="NumLinkbacks"/>&#160;
            <xsl:choose>
              <xsl:when test="NumTrackbacks &gt; 1">
                <xsl:value-of select="ebe:res('Trackbacks')"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="ebe:res('Trackback')"/>
              </xsl:otherwise>
            </xsl:choose>
					</a>
				</div>
				</div>
				<!-- close div comments -->
			</div>
		</div>
	
		<!-- close entry post -->

		</div>
		<!-- close div content -->
	</xsl:template>

	<xsl:template name="removeHtmlTags">
		<xsl:param name="html"/>
		<xsl:choose>
			<xsl:when test="contains($html, '&lt;')">
				<xsl:value-of select="substring-before($html, '&lt;')"/>
				<xsl:call-template name="removeHtmlTags">
					<!-- Recurse through HTML -->
					<xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$html" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

</xsl:stylesheet>
