XSLT: How to group entries 3 in a row?
This is an open discussion with 2 replies, filed under XSLT.
Search
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() <= 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.
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:
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:
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