Skip to content

Instantly share code, notes, and snippets.

@andrewminton
Created August 15, 2012 17:55
Show Gist options
  • Save andrewminton/3361956 to your computer and use it in GitHub Desktop.
Save andrewminton/3361956 to your computer and use it in GitHub Desktop.
<data>
<projects>
<entry id="1">paste your xml here 1</entry>
<entry id="2">paste your xml here</entry>
<entry id="3">paste your xml here</entry>
<entry id="4">paste your xml here</entry>
<entry id="5">paste your xml here</entry>
<entry id="6">paste your xml here</entry>
<entry id="7">paste your xml here</entry>
<entry id="8">paste your xml here</entry>
<entry id="9">paste your xml here</entry>
<entry id="10">paste your xml here</entry>
<entry id="11">paste your xml here</entry>
<entry id="12">paste your xml here 12</entry>
</projects>
</data>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<div class="contentwrapper">
<xsl:apply-templates select="data/projects"/>
</div>
</xsl:template>
<!-- Declare a key to identify each group of 3 elements -->
<xsl:key name="positionKey" match="//data/projects/entry" use="floor((position() - 2) div 2)"/>
<xsl:template match="data/projects">
<!-- Iterate over the first element in each group -->
<xsl:for-each select="entry[(position() - 1) mod 2 = 0]">
<ul>
<!-- Grab all elements from this group -->
<xsl:apply-templates select="key('positionKey', position()-1)"/>
</ul>
</xsl:for-each>
</xsl:template>
<xsl:template match="entry">
<li><xsl:value-of select="."/></li>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment