Search

Hi guys, any idea of how to implement each 2 entries. In example:

XML

<photoset>
    <photo ... />
    <photo ... />
    <photo ... />
    <photo ... />
    <photo ... />
    <photo ... />
</photoset>

Expected output

<ul>
    <li>
        <div>Entry 1</div>
        <div>Entry 2</div>
    </li>
    <li>
        <div>Entry 3</div>
        <div>Entry 4</div>
    </li>
</ul>

Something similar to the following:

<xsl:template match="data">
    <ul>
        <xsl:apply-templates select="photoset/photo[position() mod 2 = 1]"/>
    </ul>
</xsl:template>

<xsl:template match="photoset/photo">
    <li>
        <xsl:apply-templates select=". | following-sibling::photo[position() = 1]" mode="content"/>
    </li>
</xsl:template>

<xsl:template match="photoset/photo" mode="content">
    <div>
        Entry <xsl:value-of select="position()"/>
    </div>
</xsl:template>

This has come up a few times, and there are several approaches people take. Here are some useful discussions:

The two approaches are broadly: use recursive templates, or XPath axes (following-sibling).

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