Search

So I am trying to make a simple two coloumn table that generates as many rows as I need to. In this example it should display 4 images in two rows. I am getting errors because the table tags aren't being closed properly. But they would be closed properly if the loop actually ran. Has anyone done something similar?

<xsl:template name="vendors">
<table>
<xsl:for-each select="//vendors/entry">
        <xsl:if test="position() &lt;= 4">
    <xsl:choose>
        <xsl:when test="(position() mod 2) != 1">
            <tr><td><a href="{$root}/vendors"><img src="{$root}/image/1/125/0/uploads/{logo/filename}" /></a></td>
        </xsl:when>
        <xsl:otherwise>
            <td><a href="{$root}/vendors"><img src="{$root}/image/1/125/0/uploads/{logo/filename}" /></a>
        </td></tr>
        </xsl:otherwise>
    </xsl:choose>  
       </xsl:if>
</xsl:for-each>
</table>
</xsl:template>

This might help you :) search the forum for XSLT grouping.

<xsl:template name="vendors">
    <table>
        <xsl:apply-templates select="/data/vendors/entry[ position() mod 2 = 1 and position() &lt; 4 ]" mode="group-by-2" />
    </table>
</xsl:template>


<xsl:template match="vendors/entry" mode="group-by-2">
    <tr>
        <xsl:apply-templates select=". | following-sibling:entry[ position() &lt; 2 ]" mode="group-by-1" />
    </tr>
</xsl:template>


<xsl:template match="vendors/entry" mode="group-by-1">
    <td>
        <a href="{$root}/vendors">
            <img src="{$root}/image/1/125/0/uploads/{logo/filename}" />
        </a>
    </td>
</xsl:template>

Depending on your needs you might also find Jeni Tennison's Muenchian Method helpful given that PHP for some #&#*#@!!!! reason refuses to support xslt 2.0.

vladG,

I did search the forum before hand, but not for xslt grouping. On the other hand your example seemed promising however when testing it it only generates 2 1 column rows instead of 2 2 column rows. Also I get the same entry back in both spots.

wjnielsen,

That method is cool but unfortunately it won't help me out with this problem.

Anyways Ill keep searching for a solution

I found exactly what I was looking for here http://getsymphony.com/download/xslt-utilities/view/80505/. Which is pretty much identical to what you had vladG, I must have had a typo or something. Anyways thanks vladG and wjnielsen for the help.

Heres my final code which is more or less the same as the example provided in the link above.

<xsl:template name="vendors">
    <table>
        <xsl:apply-templates select="/data/vendors-random/entry[position() mod 2 = 1]" mode="group" />
    </table>
</xsl:template>

<xsl:template match="vendors-random/entry" mode="group">
    <tr>
        <xsl:apply-templates select=". | following-sibling::entry[position() &lt; 2]" mode="content" />
    </tr>
</xsl:template>


<xsl:template match="vendors-random/entry" mode="content">
    <td>
        <a href="{$root}/vendors">
            <img src="{$root}/image/1/125/0/uploads/{logo/filename}" />
        </a>
    </td>
</xsl:template>

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