Pages

Tuesday, August 9, 2011

XSLT Pagination and For Loop Code

For Loop 1 - 10
<xsl:call-template name="forloop">
  <xsl:with-param name="i"><xsl:value-of select="count(ts/@weekenddate)+1"/></xsl:with-param>
  <xsl:with-param name="count"><xsl:value-of select="$totalweekend"/></xsl:with-param>
</xsl:call-template>

<xsl:template name="forloop">
  <xsl:param name="i" />
  <xsl:param name="count" />
  <xsl:if test="$i <= $count"><TD align="center"> </TD></xsl:if>

  <xsl:if test="$i <= $count">
    <xsl:call-template name="for.loop">
      <xsl:with-param name="i">
        <xsl:value-of select="$i + 1"/>
      </xsl:with-param>
      <xsl:with-param name="count">
        <xsl:value-of select="$count"/>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

Pagination


<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name='page' select='Value'/>
  <xsl:param name='startpageposition' select='Value'/>
  <xsl:param name='displayrecord' select='Value'/>
  <xsl:param name='displaypage' select='Value'/>
  <xsl:include href="xslPaginationNumber.xsl"/>
  <xsl:template match="NewDataSet">
    <td class="veranda10" vAlign="middle"><td>
      <xsl:call-template name="Pagination">
        <xsl:with-param name="TotalRecord"><xsl:value-of       select="count(AgencyList/id)"/></xsl:with-param>
      </xsl:call-template>
    </td>
  </xsl:template>

<xsl:template name="Pagination">
  <xsl:param name="TotalRecord"/>
  <xsl:if test="$startpageposition > 1">
    <a><xsl:attribute name="href">javascript:SearchProfileResults(<xsl:value-of select="($displaypage * ($startpageposition -1))"/>,<xsl:value-of select="$startpageposition - 1"/>,)</xsl:attribute>«</a>
  </xsl:if>
  <xsl:if test="$startpageposition = 1">
    <xsl:text disable-output-escaping="yes">&nbsp;&nbsp;</xsl:text>
  <xsl:attribute name="href">javascript:SearchProfileResults('1','1',)</xsl:attribute>«
  </xsl:if>

  <xsl:call-template name="PaginationPublic">
    <xsl:with-param name="TotalRecord"></xsl:with-param>
    <xsl:with-param name="DisplayRecord"><xsl:value-of select="$displayrecord"/></xsl:with-param>
    <xsl:with-param name="displaypage"><xsl:value-of select="$displaypage"/></xsl:with-param>
  </xsl:call-template>
  <xsl:choose>
    <xsl:when test="ceiling($TotalRecord div ($displaypage * $displayrecord))>1 and (($displaypage *(10* $startpageposition)) < $TotalRecord)">
    <xsl:text disable-output-escaping="yes">&nbsp;&nbsp;</xsl:text>
    <a><xsl:attribute name="href">javascript:SearchProfileResults(<xsl:value-of select="($displaypage * $startpageposition) +1"/>,<xsl:value-of select="$startpageposition + 1"/>,)</xsl:attribute>»</a>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text disable-output-escaping="yes">&nbsp;&nbsp;</xsl:text>
      <xsl:attribute name="href">javascript:SearchProfileResults(<xsl:value-of select="($displaypage * $startpageposition) +1"/>,<xsl:value-of select="$startpageposition + 1"/>,)</xsl:attribute>»
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name = "PageNumberDisplay">
  <xsl:param name="aListPageNo"/>
  <xsl:param name="aListPageValue"/>
  <a><xsl:attribute name="href">subcon.aspx?page=<xsl:value-of select="$aListPageValue"/>&spage=<xsl:value-of select="$startpageposition"/></xsl:attribute><xsl:value-of select="$aListPageNo"/></a>
  </xsl:template>
</xsl:stylesheet>


<xsl:include href="xslPaginationNumber.xsl"/>
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="PaginationPublic">
  <xsl:param name="TotalRecord"/>
  <xsl:param name="DisplayRecord"/>
  <xsl:param name="displaypage"/>
  <b>Pages
  <xsl:choose>
    <xsl:when test="$TotalRecord > $DisplayRecord">
      <xsl:text disable-output-escaping="yes">&nbsp;&nbsp;</xsl:text>
      <xsl:call-template name="CountPages">
        <xsl:with-param name="startCount">
          <xsl:value-of select="(($startpageposition - 1) * $displaypage) + 1"/>
        </xsl:with-param>
        <xsl:with-param name="pagecount">
          <xsl:value-of select="ceiling($TotalRecord div $DisplayRecord)"/>
        </xsl:with-param>
        <xsl:with-param name="startpageposition">
          <xsl:value-of select="$startpageposition"/>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text disable-output-escaping="yes">&nbsp;&nbsp;</xsl:text>
      <font color="black">1</font>
    </xsl:otherwise>
  </xsl:choose>
  </b>
</xsl:template>

<xsl:template name="CountPages">
  <xsl:param name="startCount"/>
  <xsl:param name="pagecount"/>
  <xsl:param name="startpageposition"/>
  <xsl:if test="$startCount != $page">
    <xsl:call-template name="PageNumberDisplay">
      <xsl:with-param name="aListPageNo">
        <xsl:value-of select="$startCount"/>
      </xsl:with-param>
      <xsl:with-param name="aListPageValue">
        <xsl:value-of select="$startCount"/>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:if>
  <xsl:if test="$startCount = $page">
    <font color="black"><xsl:value-of select="$startCount"/></font>
  </xsl:if>
  <xsl:text disable-output-escaping="yes">&nbsp;&nbsp;</xsl:text>
  <xsl:if test="$startCount!= $pagecount">
    <xsl:call-template name="CountPages">
      <xsl:with-param name="pagecount">
        <xsl:value-of select="$pagecount"/>
      </xsl:with-param>
      <xsl:with-param name="startCount">
        <xsl:value-of select="$startCount+1"/>
      </xsl:with-param>
      <xsl:with-param name="startpageposition">
        <xsl:value-of select="startpageposition"/>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

<xsl:template name="PaginationPublicB">
  <xsl:param name="TotalRecord"/>
  <xsl:choose>
    <xsl:when test="$TotalRecord > $DisplayRecord">
      <xsl:text disable-output-escaping="yes">&nbsp;&nbsp;</xsl:text>
        <xsl:call-template name="CountPagesB">
            <xsl:with-param name="startCount">
            <xsl:value-of select="(($startpageposition - 1) * $displaypage) + 1"/>
          </xsl:with-param>
          <xsl:with-param name="pagecount">
            <xsl:value-of select="ceiling($TotalRecord div $DisplayRecord)"/>
          </xsl:with-param>
          <xsl:with-param name="startpageposition">
            <xsl:value-of select="$startpageposition"/>
          </xsl:with-param>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text disable-output-escaping="yes">&nbsp;&nbsp;</xsl:text>
      <font color="black">1</font>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
<xsl:template name="CountPagesB">
  <xsl:param name="startCount"/>
  <xsl:param name="pagecount"/>
  <xsl:param name="startpageposition"/>
  <xsl:if test="$startCount != $page">
    <xsl:call-template name="PageNumberDisplay">
      <xsl:with-param name="aListPageNo">
        <xsl:value-of select="$startCount"/>
      </xsl:with-param>
      <xsl:with-param name="aListPageValue">
        <xsl:value-of select="$startCount"/>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:if>
  <xsl:if test="$startCount = $page">
    <font color="#999999"><xsl:value-of select="$startCount"/></font>
  </xsl:if>
  <xsl:if test="(($startCount >= ((($startpageposition - 1) * $displaypage) + 1)) and ($startCount < ($startpageposition * $displaypage)) )">
    <xsl:text disable-output-escaping="yes">&nbsp;&nbsp;</xsl:text>
    <xsl:if test="$startCount!= $pagecount">
      <xsl:call-template name="CountPages">
        <xsl:with-param name="pagecount">
          <xsl:value-of select="$pagecount"/>
        </xsl:with-param>
        <xsl:with-param name="startCount">
          <xsl:value-of select="$startCount+1"/>
        </xsl:with-param>
        <xsl:with-param name="startpageposition">
          <xsl:value-of select="startpageposition"/>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:if>
  </xsl:if>
</xsl:template>
</xsl:stylesheet>

3 comments:

Srilaxmi said...
This comment has been removed by the author.
Srilaxmi said...

After implementing I'm getting error like "The named template 'PageNumberDisplay' does not exist." in xslPaginationNumber.xsl file. Could you please provide the correct code
Thanks & Regards
Srilaxmi.N

makdns said...

This blog has the file code, please see the 5th block area

thanks
mak

Post a Comment