Search

I'm building a portfolio page for a client that is using a remote DS XML file.

Each project has a comma separated list of id's for categories associated with the project.

I'm matching these categories to a list of entry id's in a preference node further up the tree to retrieve the Category name in different languages for each of the categories.

So far so good: http://xpathr.com/view/3955116/

I have language redirect working with the page and am filtering on this.

I also have the url param title filtering the correct handle and consequent ID of the entry in a template match.

My issue is when I want to filter the projects by category using a get param.

Can anyone think of a nice way to match and filter projects that contain the ID of the category when I have a string of comma separated ID's to match against?

The xpathr url has where I've got to so far and I'm struggling to undo the complication of matching a category ID against a comma separated list and then if there is a match, only show the project entries that contain a matching category ID...

My mind is positively fried... any help/pointers would be very very greatly appreciated.

Here's my take on it: http://xpathr.com/view/3956567/

Initially my thought was to use tokenize or split as you've done it for <xsl:template match="categories" mode="in">. However, doing it this way would require creating a temporary result tree, which wouldn't be the most efficient way to go about this problem.

Instead I've opted for a very straight forward solution (computationally speaking):

To find out if an id is in a comma delimited list of ids, you just need to see if the list "contains" the ID.

To elaborate, imagine an element with a set of IDs:

<categories>1,10,100</categories>

If we want to match 1, we might want to do: contains(categories, '1').

Obviously, there is a problem with this, since all three numbers contain the digit 1. We can solve this issue by prepending and appending the values with a comma: ,1,10,100,.

This way, if we match, ,1,, we'll get the ID we want.

So this is what I've done on line 69:

<xsl:apply-templates select="projects/entry[contains(concat(',', categories/cat, ','), concat(',', $category, ','))]">

Of course, you could split the stuff out into variables to make it easier to read. Anyway, here's a very different approach to your problem.

Thank you Allen. You are a true Ninja :)

The contains stuff was where I was heading but couldn't quite get the syntax right so thanks for taking the time to help me out!

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