Search

Hi,

I know how to solve it, but I'm not sure my solution is the best one.

There are entries in XML.

<entry id="1"... ></entry>
<entry id="2"... ></entry>
<entry id="3"... ></entry>
...
<entry id="50"... ></entry>

Now, I want to have them grouped in groups of three, like:

<ul>
<li>Title from entry 1</li>
<li>Title from entry 2</li>
<li>Title from entry 3</li>
</ul>
<ul>
<li>Title from entry 4</li>
<li>Title from entry 5</li>
<li>Title from entry 6</li>
</ul>
...
<ul>
<li>Title from entry 49</li>
<li>Title from entry 50</li>
</ul>

What is the best way in your opinion to achieve this?

http://www.dpawson.co.uk/xsl/sect2/N4486.html#d5509e292

This link gives some solutions, one particularly cute in my opinion:

<xsl:template match="data">
  <table>
    <xsl:for-each select="entry[position() mod $max = 1]" >
      <tr>
         <xsl:for-each select="self::entry |
          following-sibling::entry[position() < $max]>
            <td><xsl:apply-templates/></td>
         </xsl:for-each>
      </tr>
    </xsl:for-each>
  </table>
</xsl:template>

However, I don't get the "self::entry" expression in a for loop which is already iterating over "entry" nodes. In this case I would assume that "self::entry" means tag nested in another tag, but, as this the example works, it's not the case. Strange...

Wow, I'm not the only one troubled by that :) Thank you Nick!

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