Created
August 15, 2012 18:41
-
-
Save andrewminton/3362235 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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