I need to group by two different elements in my XML using XSLT. Here is sample XML:
<root>
<name>Joe</name>
<classYear>1996</classYear>
<deathDate>September 10, 2010</deathDate>
<monthName>September 2010</deathDate>
<moreInfo></moreInfo>
<link><a href="http://somelink.com">Details available here.</a></link>
</root>
<root>
<name>Sam</name>
<classYear>1981</classYear>
<deathDate>January 1, 2003</deathDate>
<monthName>January 2003</deathDate>
<moreInfo>He played on the baseball team.</moreInfo>
<link><a href="http://anotherlink.com">Details available here.</a></link>
</root>
I need to group by monthName and then classYear within that. I need to sort by monthName, classYear, and then day part of deathDate. If there is only one death announcement for the class year, I want it to display inline and then display block if there are multiple announcements for one class year in the same month.
Here is what I have so far. It groups by monthName successfully but not by classYear.
<xsl:variable name="vMonthNamesCaps" select="'|JANUARY|FEBRUARY|MARCH|APRIL|MAY|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER'"/>
<xsl:for-each select="//monthName[not(. = following::monthName)]">
<xsl:sort select="string-length(substring-before($vMonthNamesCaps,substring-before(.,' ')))" data-type="number" order="ascending" />
<H2><xsl:value-of select="."/></H2>
<xsl:for-each select="//root[monthName=current()]">
<xsl:sort select="classYear"/>
<xsl:sort select="substring-after(substring-before(deathDate,', '),' ')" data-type="number" order="ascending" />
<strong>Class of <xsl:value-of select="classYear"/>: </strong><span class="name"><xsl:value-of select="name"/></span> died on <xsl:value-of select="deathDate"/>. <xsl:value-of select="moreInfo"/>
<xsl:choose>
<xsl:when test='count(link/a) > 0'>
<xsl:copy-of select="link/a" />
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
<br /><br />
</xsl:for-each>
</xsl:for-each>
you’ll want to check
xsl:keyas a simple way to have one or more “groupBy” cursors.