Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • dalton 14 posts 34 karma points
    Jun 22, 2011 @ 18:08
    dalton
    0

    is there a way to do if test="first page" ??

    Im working on a page that that will show two different things on the first page it will show a table full of people and it will start a much longer list that will run on multiple pages.

    Basically I want it to place the table of people and  30 rows of plays on the first page and just 55 rows of plays on the rest but instead it puts 30 rows on all the pages for the first period and 55 on the pages for any other period.

    <xsl:template match="period">
        <xsl:call-template name="page_header">
            <xsl:with-param name="title" select="name" />
            <xsl:with-param name="date" select="../date" />
            <xsl:with-param name="venue" select="../venue" />
            <xsl:with-param name="home" select="../homeTeam/name" />
            <xsl:with-param name="visitor" select="../visitorTeam/name" />
        </xsl:call-template>
        <br/>
        <xsl:choose>
            <xsl:when test="position() = 1">
    
                <!-- Starters table -->
                <table cellspacing="0" cellpadding="0" class="startersOuter">
                  <tr class="rowheight">
                    <td width="40%" class="stheader homehead"><xsl:value-of select="../homeTeam/name"/> Starters:</td>
                    <td width="20%"></td>
                    <td width="40%" class="stheader visitorhead"><xsl:value-of select="../visitorTeam/name"/> Starters:</td>
                  </tr>
                  <tr class="rowheight">
                    <td width="40%"><xsl:apply-templates select="../players/homePlayers"/></td>   
                    <td width="20%"></td>
                    <td width="40%"><xsl:apply-templates select="../players/visitorPlayers"/></td>
                  </tr>
                </table>
    
                <!-- Play list -->
                <xsl:for-each select="play">
    
                    <table cellspacing="0" cellpadding="0" class="content">
                        <xsl:apply-templates select="."/> 
                    </table>  
    
                    <!-- 30 rows per page-->
                    <xsl:if test="(position() mod 30) = 0">
                        <br/>
                        <div style="page-break-after: always"></div>                
                        <xsl:call-template name="page_header">
                            <xsl:with-param name="title" select="../name" />
                            <xsl:with-param name="date" select="../../date" />
                            <xsl:with-param name="venue" select="../../venue" />
                            <xsl:with-param name="home" select="../../homeTeam/name" />
                            <xsl:with-param name="visitor" select="../../visitorTeam/name" />
                        </xsl:call-template>                  
                        <br/>
                    </xsl:if>
                </xsl:for-each>   
                <div style="page-break-after: always"></div>
            </xsl:when>
            <xsl:otherwise>
                <xsl:for-each select="play">
    
                    <table cellspacing="0" cellpadding="0" class="content">
                        <xsl:apply-templates select="."/>
                    </table>
    
                    <!--55 rows per page-->
                    <xsl:if test="(position() mod 55) = 0 ">
                        <br/>
                        <div style="page-break-after: always"></div>                
                        <xsl:call-template name="page_header">
                            <xsl:with-param name="title" select="../name" />
                            <xsl:with-param name="date" select="../../date" />
                            <xsl:with-param name="venue" select="../../venue" />
                            <xsl:with-param name="home" select="../../homeTeam/name" />
                            <xsl:with-param name="visitor" select="../../visitorTeam/name" />
                        </xsl:call-template>
                        <br/>
                    </xsl:if>
    
                </xsl:for-each>
            </xsl:otherwise>
        </xsl:choose> 
      </xsl:template>

    If you have any clue of a way to fix this it would be much appreciated. In my mind it would just be so much easier to have a first page function but im welcome to any ideas.

    Thanks, Dalton

  • Richard 146 posts 168 karma points
    Jun 22, 2011 @ 18:27
    Richard
    0

    Dalton,

    Assuming that when you say "first page", you are paginating through the data on the same URL so using a QueryString value to find the page of results. You can get the current page with

    <xsl:variable name="qStringPage" select="umbraco.library:RequestQueryString('page')"/>

    <xsl:variable name="page">
    <xsl:choose>
    <!-- first page -->
    <xsl:when test="number($qStringPage) &lt;= 1 or string($qStringPage) = '' or string(number($qStringPage)) = 'NaN'">
    1
    </xsl:when>
    <!-- what was passed in -->
    <xsl:otherwise>
    <xsl:value-of select="number($qStringPage)"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    and then set a variable for the number of records to display with

    <xsl:variable name="noRecords">
    <xsl:choose>
    <!-- all the rest (on the last page) -->
    <xsl:when test="$page = 1">
    <xsl:value-of select="30"/>
    </xsl:when>
    <!-- only the appropriate number for this page -->
    <xsl:otherwise>
    <xsl:value-of select="55"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    and then control the records that are displayed with a calculation on the page number and number of records to display, remembering that the first is 30 and then other pages have a different number (55).

  • dalton 14 posts 34 karma points
    Jun 22, 2011 @ 18:52
    dalton
    0

    Thanks a lot Im pretty sure that will work but Im just not sure where to apply the two variables?

  • Richard 146 posts 168 karma points
    Jun 23, 2011 @ 10:23
    Richard
    0

    Do a calculation to work out the rows that you want to display on that pagination view, e.g. page 3 would be like (just need to extend for special case on the first page:

    <xsl:variable name="startPos" select="30 + (($page - 1) * 55)"/>

    <xsl:variable name="endPos" select="$startPos + 55"/>

    and then when you are writing out the rows when the position is within this range

     

    <xsl:for-eachselect="play">
    <xsl:if test="Position() &gt; $startPos and Position &lt; $endPos">
    <xsl:comment>Write out row</xsl:comment>
    ....
    </xsl:if>
    </xsl:for-each>
Please Sign in or register to post replies

Write your reply to:

Draft