Sorting Sitecore data to multicolumn html table

Sitecore, XSLT Add comments

Sorting Sitecore data to multicolumn html table is quite hard in XSLT because data in XML is not sorted by item/@sortorder.

I finally found out how to do this so it will actually work and I am not loosing data. The trick is creating data first into a flat XML Nodeset and looping this data then to a multicolumn table using following-sibling::item commands. Here is the small sample code for this where I take abstract content structure from the Sitecore to a XML Nodeset <ul><li>xxxxxx</li></ul>.

First let’s make a variable.

<xsl:variable name=”keywords”>
<ul>
<xsl:for-each select=”$keywords”>
<xsl:for-each select=”descendant-or-self::item[(@template='keywords')]“>
<li>
<xsl:value-of select=”sc:fld(’text’,.)”/>
</li>
</xsl:for-each>
</xsl:for-each>
</ul>
</xsl:variable>

Then using msxsl:node-set -function (http://msdn2.microsoft.com/en-us/library/hz88kef0(vs.71).aspx) I create nodeset out of the XSL variable and loop data to the html table.

<table>
<xsl:for-each select=”msxsl:node-set($keywords)/ul/li[position() mod 3 = 1]“>
<tr>
<td>
<xsl:value-of select=”.”/>
</td>
<xsl:for-each select=”following-sibling::li[position() < 3]“>
<td>
<xsl:value-of select=”.”/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>

I would be very keen to know if you have done this in pure XSLT because msxsl:node-set seems to be quite slow.

One Response to “Sorting Sitecore data to multicolumn html table”

  1. Lars Nielsen Says:

    Nice. Thanks for sharing your experiences.

Leave a Reply

Check Spelling
Activate Spell Check while Typing
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in