xsl-list
[Top] [All Lists]

Re: [xsl] pagination - From PHP To XSL - Recursion ?

2008-02-02 11:26:08
Hello Michael,

   Thank you for your reply.

Sorry, i want to say

1. <xsl:variable name="total" select="12"/>
2. <xsl:variable name="current" select="1"/>
3. <xsl:variable name="interval" select="2"/>

4. <xsl:variable name="first" select="$current - $interval" />
5. <xsl:variable name="last" select="$current + $interval" />

<!-- adjust -->

How to make it correctly in XSL?
-----------------------------------
6. <xsl:if test="$first &lt; 1">

7.     $last = $last - ($first -1)            //Error  - I know it
8.     $first = 1                                 //Error  - I know it
9. </xsl:if>


10. <xsl:if test="$last > $total">

11.     $first = $first - ($last - $total)        //Error - I Know it
12.     $last=total                                  //Error - I Know it

13.     <xsl:if test="$first &lt; 1">
14.             $first=1                               //Error - I Know it
15.     </xsl:if>

16. </xsl:first>
------------------------------------



17. <xsl:call-template name="pagination-item">
18.        <xsl:with-param name="current" select="$current"/>
19.        <xsl:with-param name="p" select="$first"/>
20.        <xsl:with-param name="last" select="$last"/>
             <xsl:with-param name="script" select="home.px"/>
21. </xsl:call-template>


.......

<xsl:template name="pagination-item">
       <xsl:param name="p"></xsl:param>
       <xsl:param name="current"></xsl:param>
       <xsl:param name="last"></xsl:param>
       <xsl:param name="script"><xsl:value-of select="script"/></xsl:param>

       <xsl:if test="$p &lt; $last+1">
           <xsl:choose>
                   <xsl:when test="$p=$current">
                           <xsl:value-of select="$p"/>
                   </xsl:when>
                   <xsl:otherwise>
                       <a>
<xsl:attribute name="href"><xsl:value-of select="$script"/>&amp;page=<xsl:value-of select="$p"/></xsl:attribute>
                           <xsl:value-of select="$p"/>
                       </a>
                  </xsl:otherwise>
            </xsl:choose>
       </xsl:if>


   <xsl:call-template name="pagination-item">
       <xsl:with-param name="p" select="$p+1"></xsl:with-param>
       <xsl:with-param name="current" select="$current"></xsl:with-param>
       <xsl:with-param name="last" select="$last"></xsl:with-param>
       <xsl:with-param name="script" select="$script"></xsl:with-param>
   </xsl:call-template>

</xsl:template>

.....

I want to implement pagination

Ej: 10 pages
no_link : current
Page:                                                      _ : link
1            1      2_   3_    4 _   5_
2            1_    2     3_    4_    5_
3            1_    2_   3      4_    5_
4            2_    3_   4      5_    6_
5            3_    4_    5     6_    7_
6            4_    5_    6     7_    8_
7            5_    6_    7     8_    9_
8            6_    7_    8     9_    10_
9            6_    7_    8_   9      10_
10          6_    7_    8_    9_    10


Thanks for your time and input!



---- Mensaje original ----- De: Michael Kay
Para: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Enviado: sábado, 02 de febrero de 2008 15:38
Asunto: RE: [xsl] pagination - From PHP To XSL - Recursion ?


Not understanding either PHP or Spanish, I'm a bit disadvantaged here. But
in any case, trying to reverse-engineer procedural code and turn it into
declarative code is usually not the best way to go about things. You often
need a completely different approach. It would be better to describe the
inputs and outputs of your transformation, and work from there.

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Alejandro [mailto:alexcontini(_at_)terra(_dot_)es]
Sent: 02 February 2008 15:17
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] pagination - From PHP To XSL - Recursion ?

Hello, i want to calculate and to catch the final result of
the variables $_pagi_nav_desde and  $_pagi_nav_hasta to pass
them to one template. I don´t know to make it in XSL, because
i know that in XSL the variables can´t to change. Can you
help me, please?

Cheers,
Alexander


//  PHP Code//

// Calculamos desde que numero de pagina se mostrara
$_pagi_nav_desde = $_pagi_actual - $_pagi_nav_intervalo;  //
Calculamos hasta que numero de pagina se mostrara
$_pagi_nav_hasta = $_pagi_actual + $_pagi_nav_intervalo;

 // Ajustamos los valores anteriores en caso sean resultados
no válidos

 // Si $_pagi_nav_desde es un numero negativo
if($_pagi_nav_desde < 1){
          // Le sumamos la cantidad sobrante al final para
mantener el numero de enlaces que se quiere mostrar.
          $_pagi_nav_hasta -= ($_pagi_nav_desde - 1);
          // Establecemos $_pagi_nav_desde como 1.
          $_pagi_nav_desde = 1;
 }

 // Si $_pagi_nav_hasta es un numero mayor que el total de
paginas  if($_pagi_nav_hasta > $_pagi_totalPags){
      // Le restamos la cantidad excedida al comienzo para
mantener el numero de enlaces que se quiere mostrar.
      $_pagi_nav_desde -= ($_pagi_nav_hasta - $_pagi_totalPags);
      // Establecemos $_pagi_nav_hasta como el total de paginas.
      $_pagi_nav_hasta = $_pagi_totalPags;

      // Hacemos el ultimo ajuste verificando que al cambiar
$_pagi_nav_desde no haya quedado con un valor no valido.
      if($_pagi_nav_desde < 1){
           $_pagi_nav_desde = 1;
        }
 }


// XSL Code //
<xsl:call-template name="pagination-item">
        <xsl:with-param name="current" select="$curpage"/>
        <xsl:with-param name="p" select="$_pagi_nav_desde"/>  ??
        <xsl:with-param name="last" select="$_pagi_nav_hasta"/>   ??
        <xsl:with-param name="script" select="$script"/>
</xsl:call-template>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--