Search

Hi folks,

currently I’m working on a new project with symphony and came up with a problem. First let me try to explain what I wanna do:

I got a list of x entries. All of those should show up on in little boxes. CSS is set to display 3 boxes in a row (float:left). Each time a new row starts a separate DIV-element should appear. So far so good and not really complex:

<div id="container" class="container_16 clearfix">
<div class="grid_2">first element</div>

<xsl:for-each select="src/entry">

<xsl:if test="count(preceding-sibling::*[@id]) mod 4 = 0">

<div class="grid_2">new line</div>

</xsl:if>

<div class="grid_4">
<a href="#"><xsl:value-of select="value"/>:<xsl:value-of select="title"/></a>
</div>

</xsl:for-each>
</div>

Each time we reach third element in for-each I wanna close and reopen a div wrapper do clear float and start new. What I did is:

<div id="container" class="container_16 clearfix">
<div class="grid_2">first element</div>

<xsl:for-each select="src/entry">

<xsl:if test="count(preceding-sibling::*[@id]) mod 4 = 0">
</div>
<div class="container_16 clearfix">
<div class="grid_2">new line</div>

</xsl:if>

<div class="grid_4">
<a href="#"><xsl:value-of select="value"/>:<xsl:value-of select="title"/></a>
</div>

</xsl:for-each>
</div>

So what happens is symphony showing “parser error : Opening and ending tag mismatch: div line 32 and xsl:if” Maybe someone able to help? Maybe my whole concept is a bad way to do such grouping?

Thanks Maik

There was a thread on this topic just a few days ago.

It seems like you’re coming from one of the other proprietary templating languages. In XSLT you cannot do

while(entries) {
   if(test) {
      <div>
   }
<p>
   Text
</p>
   if(test) {
      </div>
   }
}

as <div> is missing its closing tag as if() consists of XML tags as well.

Something like the following might work:

<xsl:template match="data">
    <xsl:apply-templates select="src/entry[position() mod 3 = 1]"/>
</xsl:template>

<xsl:template match="src/entry">
    <div class="container_16 clearfix">
        <div class="grid_2">new line</div>
        <xsl:apply-templates select=". | following-sibling::entry[position() &lt;= 2]" mode="content"/>
    </div>
</xsl:template>

<xsl:template match="src/entry" mode="content">
    <div class="grid_4">
        <a href="#"><xsl:value-of select="value"/>:<xsl:value-of select="title"/></a>
    </div>
</xsl:template>

Thanks phoque. Works fine. Yes. I’m not that familiar with XSLT, but learning. It’s so fascinating!

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