Skip to content

Instantly share code, notes, and snippets.

@spdustin
Created July 7, 2015 20:01
Show Gist options
  • Save spdustin/801e1a6550a559461592 to your computer and use it in GitHub Desktop.
Save spdustin/801e1a6550a559461592 to your computer and use it in GitHub Desktop.
XSL Example - Group by year from "date"
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:key name="group-by-group" match="Row" use="@Group"/>
<xsl:key name="group-by-year" match="Row" use="substring(@date,4,4)"/>
<xsl:template match="/">
<ul>
<xsl:apply-templates select="/dsQueryResponse/Rows/Row[count(. | key('group-by-year', substring(@date,4,4))[1]) = 1]" mode="header">
<xsl:sort select="substring(@date,4,4)"/>
</xsl:apply-templates>
</ul>
</xsl:template>
<xsl:template match="Row" mode="header">
<li><xsl:value-of select="substring(@date,4,4)"/>
<ul>
<xsl:apply-templates select="key('group-by-year',substring(@date,4,4))" mode="content">
<xsl:sort select="substring(@date,4,4)"/>
<xsl:sort select="substring(@date,9,2)"/>
<xsl:sort select="substring(@date,12,2)"/>
</xsl:apply-templates>
</ul>
</li>
</xsl:template>
<xsl:template match="Row" mode="content">
<li>
<xsl:value-of select="@Title"/>
<xsl:value-of select="substring(@date,4,4)"/>-<xsl:value-of select="substring(@date,9,2)"/>-<xsl:value-of select="substring(@date,12,2)"/>
</li>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment