generating a table in a template
This is an open discussion with 4 replies, filed under XSLT.
Search
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() < 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() < 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() < 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.
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?