Skip to content

Instantly share code, notes, and snippets.

@andrewminton
Created August 15, 2012 18:41
Show Gist options
  • Save andrewminton/3362235 to your computer and use it in GitHub Desktop.
Save andrewminton/3362235 to your computer and use it in GitHub Desktop.
<TestDocument>
<Element>Alpha</Element>
<Element>Bravo</Element>
<Element>Charlie</Element>
<Element>Delta</Element>
<Element>Echo</Element>
<Element>Foxtrot</Element>
<Element>Golf</Element>
<Element>Hotel</Element>
</TestDocument>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<!-- Declare a key to identify each group of 3 elements -->
<xsl:key name="positionKey" match="TestDocument/Element" use="floor((position() - 2) div 3)"/>
<xsl:template match="TestDocument">
<html>
<!-- Iterate over the first element in each group -->
<xsl:for-each select="Element[(position() - 1) mod 3 = 0]">
<ul>
<!-- Grab all elements from this group -->
<xsl:apply-templates select="key('positionKey', position()-1)"/>
</ul>
</xsl:for-each>
</html>
</xsl:template>
<xsl:template match="Element">
<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