Search

I have a for-each loop on one of my pages, but I’m needing to inject some HTML code after every 3 items in the loop, how could I go about this in XSL?

So I should end up with something like this:

Item One
Item Two
Item Three
some HTML code
Item Four
Item Five
Item Six
some HTML code
Item Seven
Item Eight
Item Nine
some HTML code

If your using a Loop to Output your data, this would work:

<xsl:for-each select="/data/item">
    <!-- Item Output -->
    <xsl:if test="position() mod 3 = 0">
        <!-- Some HTML here -->
    </xsl:if>
</xsl:for-each>

(Only Tested it in Xselerator)

@michael-e: Thanks for the link!

@zippo, that worked well, as I was using a for-each, I opted for that. I must start using the apply-template technique instead mind!

If your using a Loop to Output your data, this would work:

It will also only work if you don’t have to wrap your groups of three inside another element.

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