Search

Got a little stuck in filtering items. Still new to Symphony and looked up allot of forum threads, but none of them gave me the real explanation. I have a page which loads all my items that works perfectly. Now I added a selectbox on top of the page to filter the items on recommendation, name or price.

So this is what I have: - A datasource for my items called ‘Resorts’ - In the datasource I created a filter param for a select box, name, and prices ($ds-recommended, $ds-name, $ds-price) - I created a param for the page called $url-filter

This is my get form:

<form action="{$root}/resorts/" method="get">
       <fieldset>
           <select name="filter">
              <option value="name">Name</option>
              <option value="price">Price</option>
              <option value="recommended">Recommended</option>
           </select>
           <button type="submit" value="submit">Search</button>
       </fieldset>
   </form>

My for each statement (that doesn’t work):

<xsl:for-each select="data/resorts/entry[filter/$url-filter]">

My XSL:

<data>
    <events />
    <resorts>
        <pagination total-entries="11" total-pages="2"
        entries-per-page="10" current-page="1" />
        <section id="9" handle="resorts">Resorts</section>
        <entry id="114">
            <price handle="1200">1200</price>
            <recomended>No</recomended>
            <lipe-green-aware-resort>No</lipe-green-aware-resort>
            <name>Baja Resort</name>
        </entry>
    </resorts>
</data>

How do I filter my items on these params?

Thanks

I believe you are not trying to ‘filter’ your results, but to sort them. Am I right? If that’s the case, you could use a xsl:sort to sort your XSL-results:

<xsl:for-each select="data/resorts/entry">
    <xsl:sort select="$url-filter" />
    ...some magic mumbo jumbo...
</xsl:for-each>

Another note: you do not need to ‘define’ a url-parameter for your page, everything that comes with a GET automaticly becomes an available parameter with a $url--prefix.

Hmm yeah you’re right, I was so focused on filtering it, that sorting is probably a better way. But unfortunately it still doesn’t work.

<xsl:sort select="resort-name" order="ascending" />

I tried to use that one, to test it manually, because the $url-filter isn’t working. But he doesn’t sort on this one also. But on some nodes he does sorts.
So that’s a bit weird. The sort ‘resort-name’ should work? It doesn’t do anything now. Am I overlooking something?

I don’t see a field called ‘resort-name’ in your example XML:

<entry id="114">
    <price handle="1200">1200</price>
    <recomended>No</recomended>
    <lipe-green-aware-resort>No</lipe-green-aware-resort>
    <name>Baja Resort</name>
</entry>

Are you sure it’s there? The XSL only ‘sees’ the XML provided by Symphony.

No sorry I didn’t put it in the example code. It’s different to make it easier to explain.
Let me put it this way, I used your way of sorting:

    <xsl:sort select="$url-filter" />

When I press submit, $url-filter gets filled with the value of the option and passes it trough to the URL. But the items doesn’t get sorted. So somehow the value doesn’t reach the sorting?

I think I know what’s wrong. You need to sort by the name of your xml-field. The value of $url-filter is not the reference to the element, but the name of the element.

Try this:

<xsl:sort select="*[name() = $url-filter]" />

Haven’t tried this yet for myself, but I think it should work.

Yeah that works!, kind of… If i remove the ?filter= from the url, i get a bunch of errors. (see image).

Also the sorting doesn’t work for all nodes in the xml? What can that be?

Thanks

Attachments:
Symphony – XSLT Processing Error_1288088397058.png

You get the errors because the $url-filter is not defined when you don’t put it in your URL. Setting a default value for this fixes this problem. You can do this by adding a <xsl:param /> to your stylesheet, outside your <xsl:template /> -tag:

<xsl:param name="url-filter" select="'resort-name'" />

The above example sets the default value of $url-filter to ‘resort-name’. Note the single quotes (”) to determine ‘resort-name’ as a string, instead of resort-name the xpath expression.

Aah yes, Thanks Kanduvisla, that explains allot,

Another question. How do I set my xsl:sort if I want to sort on prices ‘higher then..’ and ‘Lesser then..’ but also keep the resort-name sorting? So there is only one xsl:sort.

Thanks

@Strangerr - This article on “Fancy sorting” from Rowan Lewis (buzzomatic) might be helpful to you.

I try to sort e.g. recommended resorts which is a checkbox with a Yes or No trigger.

in my form i use the node name for sorting which is ‘recommended’. When I sort it, nothing happens, it just sorts the names??

@Strangerr - Would you mind posting your XML and XSLT on pastie.org and post the links to the code here?

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