Search

Maths is not my strong point, and I'm stuck.

I've looked through the forum at every post that I can find that mentions lists, splitting lists, modulo etc, but it makes little sense to me to achieve what I need...

I need to split up my entries into groups of 6. I have to start from entry[position() >= 2], which I have in a variable called $entries as the first entry is a feature and handled separately. My intended output is a list for every 6 items out of that variable.

Anyone have any ideas?

This utility from attachment might be a good place to start :)

Give it:

  • the entries from Datasource
  • the index of the column desired (1,2,3)
  • the number of items to return (6 in your case)
  • a modulo value that can be applied to entries (in case you want every n-th entry from the ones you supplied)

This works best with @nick's iterator template.

Show me the XML output and the needed HTML structure and I'll give you a hand.

Attachments:
filter-entries.xsl

Problem is I have no XML, as there's no content yet. Dummy XML is

<?xml version="1.0" encoding="UTF-8"?>

<data>
    <pants>
        <entry>
            <content>Test 1</content>
        </entry>
        <entry>
            <content>Test 2</content>
        </entry>
        <entry>
            <content>Test 3</content>
        </entry>
        <entry>
            <content>Test 4</content>
        </entry>
        <entry>
            <content>Test 5</content>
        </entry>
        <entry>
            <content>Test 6</content>
        </entry>
        <entry>
            <content>Test 7</content>
        </entry>
        <entry>
            <content>Test 8</content>
        </entry>
        <entry>
            <content>Test 9</content>
        </entry>
        <entry>
            <content>Test 10</content>
        </entry>
        <entry>
            <content>Test 11</content>
        </entry>
        <entry>
            <content>Test 12</content>
        </entry>
        <entry>
            <content>Test 13</content>
        </entry>
        <entry>
            <content>Test 14</content>
        </entry>
    </pants>
</data>

Expected output is:

<aside>
    <ul>
        <li>Test 2</li>
        <li>Test 3</li>
        <li>Test 4</li>
        <li>Test 5</li>
        <li>Test 6</li>
        <li>Test 7</li>
    </ul>
</aside>
<aside>
    <ul>
        <li>Test 8</li>
        <li>Test 9</li>
        <li>Test 10</li>
        <li>Test 11</li>
        <li>Test 12</li>
        <li>Test 13</li>
    </ul>
</aside>
<aside>
    <ul>
        <li>Test 14</li>
    </ul>
</aside>

would it be as simple as using a recursive template and checking that the

position() mod 6 = 0

??

With a slight modification, that works. Cheers!

The modification was to remove the first entry from the list as that is taken care of separately. I made a variable that copied the entries, but not position 1.

Thanks very much!

Your solution is almost correct. The only issue: Xpath starts counting at 1 not at 0, so the correct modulo expression is

pants/entry[position() mod 6 = 1]

also, that huge "following-sibling" expression can be simplified to

. | following-sibling::entry[position() &lt; 6]

Oh, thanks.

Thanks dudes!

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