Search

Hello,
I have a xpath predicate that sounds like this:

<xsl:apply-templates select="/data/navigation/page[not(types/type = 'hidden') and not(types/type = 'admin')]"/>

In the same statement I need to restrict the number of results with position(), so

<xsl:apply-templates select="/data/navigation/page[not(types/type = 'hidden') and not(types/type = 'admin') and position() = 3]"/>

In a list of 12 items, I need to get the first 3, then the second three, then the third and so on. I guess I have to do position() > 0 and &lt; 4. Still, testing just the single position does not work.

Thanks!

If I understand what you want to do correctly, I'm guessing the issue is that the position() function is within the page[not...] predecate. I expect you got all the pages that:

  • aren't hidden;
  • aren't admin;
  • aren't the third?

Try something like:

page[not(types/type = 'hidden') and not(types/type = 'admin')][position() > 0 and position() < 4]

which is this syntax:

page[not...][]

However, I suspect the position may be based on the whole set of pages rather than just the pages which aren't hidden or admin. If that's not what you want, maybe you could create an exsl:node-set() of pages which aren't hidden or admin and then do your position-based selecting on that node set. ("Multi-step processing.") On the other hand, perhaps some XSLT ninja here can do it without node-set().

Thanks David,
as you say the page[][] works partially, each apply-templates tag resets the position counter to 1. I'm looking into the exsl branch :)

Thinking about it more, my guess was probably wrong as it looks like your nots were okay. What was the result you were originally getting - no pages at all because the third page was filtered out by the hidden and admin types?

Let me know how you get on with exsl. If I remember correctly I found that they're already installed and available to use in Ubuntu and I just had to add the namespace.

Maybe a simpler option would be to create an additional navigation datasource that filters out the admin and hidden types.

David,
can't say why, (probably because it is correct :), but this works

<xsl:apply-templates select="/data/navigation/page[not(types/type = 'hidden') and not(types/type = 'admin')][position() &gt;= 1 and position() &lt;= 3]"/>
<xsl:apply-templates select="/data/navigation/page[not(types/type = 'hidden') and not(types/type = 'admin')][position() &gt;= 4 and position() &lt;= 6]"/>

Thanks!

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