On many occasions you’ll want to group items under a header, but control the order of the group display. The problem here is that when you select your group by field, you can only sort that group alphabetically ascending or descending. A quick fix is to prepend a numeric value to the field your grouping.
For example, if I have a list of approved catering restaurants and grouped into cuisine types and I want the most popular ‘pizza’ group on top. Rather than cuisine names Asian, Burgers, Cold cuts, Pasta, Pizza; I would use 01_Pizza, 02_Asian, 03_Cold cuts, 04_Pasta, 05_Burgers.
If you’ve done that, the next question your going to get from the customer is “Can we get rid of the leading number?” Yes, yes you can.
In your ContentQueryMain.xsl, add in this new template: OuterTemplate.RemovePrependedOrderDigits
<xsl:template name=”OuterTemplate.RemovePrependedOrderDigits”>
<xsl:param name=”GroupName”/>
<xsl:choose>
<xsl:when test=”contains($GroupName,’_')”>
<xsl:variable name=”OrderBits”>
<xsl:value-of select=”substring-before($GroupName,’_')”/>
</xsl:variable>
<xsl:choose>
<xsl:when test=”translate($OrderBits,’0123456789′,”) = ””>
<xsl:value-of select=”substring-after($GroupName,’_')”/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=”$GroupName”/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=”$GroupName”/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Then update the out of the box template, OuterTemplate.GetGroupName to call your new template.
<xsl:template name=”OuterTemplate.GetGroupName”>
<xsl:param name=”GroupName”/>
<xsl:param name=”GroupType”/>
<xsl:choose>
<xsl:when test=”string-length(normalize-space($GroupName)) = 0″>
<xsl:value-of select=”$BlankGroup”/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test=”$GroupType=’URL’”>
<xsl:variable name=”Url”>
<xsl:call-template name=”OuterTemplate.FormatValueIntoUrl”>
<xsl:with-param name=”Value” select=”$GroupName”/>
</xsl:call-template>
</xsl:variable>
<xsl:call-template name=”OuterTemplate.GetPageNameFromUrlRecursive”>
<xsl:with-param name=”Url” select=”$Url”/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name=”OuterTemplate.RemovePrependedOrderDigits”>
<xsl:with-param name=”GroupName” select=”$GroupName”/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Caveat: You’ll need to communicate that this numeric removal only takes place when groupings are prepended with a number and an underscore.










