Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan 1288 posts 3921 karma points c-trib
    Aug 14, 2010 @ 01:21
    Dan
    0

    Simple table row example with XSLT templates

    Hi,

    I have a long list of nodes, which I'd like to display in a simple tabular grid, with three columns and many rows.  How would this be done using XSLT templates, as I'm struggling to find an example anywhere?

    I've tried the following, but can't seem to get it to loop through the td's three times per tr.  Everything I've tried just puts each td in a new tr:

    <xsl:template match="/">
      <table>
        <xsl:apply-templates select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']" mode="table-row" />
      </table>
    </xsl:template>

    <xsl:template match="*[@isDoc]" mode="table-row">
      <tr>
        <xsl:apply-templates select="." mode="table-cell" />
      </tr>
    </xsl:template>

    <xsl:template match="*[@isDoc]" mode="table-cell">
      <td><xsl:value-of select="@nodeName"/></td>
    </xsl:template>

    Can anyone suggest how to do this?

    Thanks

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Aug 14, 2010 @ 12:21
    Chriztian Steinmeier
    3

    Hi Dan,

    You're off to a good start already, you just need to find out how to only start every third row, right?

    Take a look at the answer I posted here: http://our.umbraco.org/forum/developers/xslt/11527-Problem-with-listing-HTLM-strcuture-with-XSLT

    It's for a 2-column table, but can be modified for your example - something along the lines of this:

    <xsl:template match="/">
      <table>
        <xsl:apply-templates select="$currentPage/*[@isDoc][position() mod 3 = 1]" mode="table-row" />
      </table>
    </xsl:template>
    
    <xsl:template match="*[@isDoc]" mode="table-row">
      <tr>
        <xsl:apply-templates select=". | following-sibling::*[@isDoc][position() &lt; 3]" mode="table-cell" />
      </tr>
    </xsl:template>
    
    <xsl:template match="*[@isDoc]" mode="table-cell">
      <td><xsl:value-of select="@nodeName"/></td>
    </xsl:template>
    

    /Chriztian

  • Dan 1288 posts 3921 karma points c-trib
    Aug 14, 2010 @ 22:06
    Dan
    0

    Perfect, thanks Chriztian!

  • Bas Schouten 135 posts 233 karma points
    Oct 11, 2010 @ 16:21
    Bas Schouten
    0

    Hi All,

    I made a similar table with xslt. But is there a way to fill up empty table cells?

     

Please Sign in or register to post replies

Write your reply to:

Draft