Search

OK so I’m in a slightly unique position here. I’m building a search page that uses pagination and, obviously, I’d like to keep the URL parameters when I switch form page to page in the pagination scheme. Problem is, by default clicking the link removes all URL parameters.

But I have a solution. I just don’t know how exactly to implement it. Basically I figure I can add a variable to the URL I’m generating and have that variable be populated based on what parameters are available.

Here’s where I am so far:

<xsl:call-template name="pagination">
    <xsl:variable name="url" select="'/entries'"/>
    <xsl:if test="$url-param1 != ''">
        Add '/param1:{$url-param1}'
    </xsl:if>
    <xsl:if test="$url-param2 != ''">
        Add '/param2:{$url-param2}'
    </xsl:if>
    <xsl:if test="$url-param3 != ''">
        Add '/param3:{$url-param3}'
    </xsl:if>
    <xsl:if test="$url-param4 != ''">
        Add '/param4:{$url-param4}'
    </xsl:if>
    [...]
    <xsl:with-param name="pagination-element" select="/data/listings/pagination" />
    <xsl:with-param name="display-number" select="'10'" />
    <xsl:with-param name="url" select="{$url}/$" />
</xsl:call-template>

The problem is I don’t know how to concatenate onto my URL based on a series of If-statements. How would this be done? This is just an example. In reality there are 10 URL parameters to test for.

You’ll want to use recursion to do this. Write a named template that conditionally passes the count and previous url string to itself. To dynamically generate the param name to test, you can use the exsl dyn:evaluate function.

Let me know if you need more. Just not in a recursive mood right now.

I get what you mean, but each param is not actually named “param#” but instead they all have different names.

The above is just a stripped down example for simplicity’s sake. Sorry for the mixup.

OK, I figured out how to do it by using If-statements inside a variable—never knew you could do that…—but I have to have all the Ifs on one line otherwise it adds spaces between the the content added by the Ifs.

Is there anything I can do about this? It’s not too big of a deal, just a bit harder to maintain my code.

Make sure you wrap your content with <xsl:text>content</xsl:text> to avoid any unwanted spaces.

You can concatenate the pieces directly in the with-param if you like:

<xsl:with-param name="url">
    <xsl:text>/entries</xsl:text>
    <xsl:if test="$url-param1 != ''">
        <xsl:text>/param1:</xsl:text>
        <xsl:value-of select="$url-param1"/>
    </xsl:if>
    ...
    <xsl:text>/$/</xsl:text>
</xsl:with-param>

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details