Adding subgroup in Table of Contents page

matthew.wren's Avatar

matthew.wren

08 Sep, 2015 02:20 PM

On one of our microsites we have a Table of Contents page that indexes through folders pulling out the articles within their own folder. However one of the folders, by its nature, has far more articles than the others and we would like to create some kind of sub-grouping under this folder to organize it more. Here's the page in question with One the Commons being the folder with the most articles.

My idea is to add another folder within the On The Commons folder and then create a styling that's different but will sit underneath the One The Commons information on the TOC. I attached an image where you can see the fold test within On The Commons.

I think the only thing I would need to do is add code to the format to display folder content that's a child of the main folder groups but I'm not sure how to accomplish that. Here's the format that creates the TOC, how do I add a conditional that, when there's a subfolder, will display the content under the main folder?

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes" method="xml"/>
<xsl:variable name="issues-base">/alumni/journal/issues/</xsl:variable>
<xsl:variable name="root-folder">
    <xsl:value-of select="concat($issues-base,substring-before(substring-after(//system-page[@current='true']/path,$issues-base),'/'),'/',substring-before(substring-after(substring-after(//system-page[@current='true']/path,substring-before(substring-after(//system-page[@current='true']/path,$issues-base),'/')), '/'), '/'), substring-before(substring-after(substring-after(//system-page[@current='true']/path, substring-before(substring-after(substring-after(//system-page[@current='true']/path,substring-before(substring-after(//system-page[@current='true']/path,$issues-base),'/')), '/'), '/')), $issues-base),'/'))"/>
</xsl:variable>
<xsl:variable name="default-page-name">index</xsl:variable>

<xsl:template match="system-index-block">
    <xsl:variable name="root-folder">
        <xsl:for-each select="//system-page[@current='true']/ancestor::system-folder">
            <xsl:if test="position() = 2">
                <xsl:value-of select="path"/>
            </xsl:if>
        </xsl:for-each>
    </xsl:variable>
    <div class="contentsArticleSection message"><a href="[system-asset]{$root-folder}/contents/presidents-message[/system-asset]">A Message from the President</a></div> 
    <xsl:apply-templates mode="root-folder" select="//system-folder[path = $root-folder]"/>
         
</xsl:template>

<xsl:template match="system-folder" mode="root-folder">
    <xsl:apply-templates mode="top-level" select="system-folder[display-name!=''] | system-page[display-name != '' and name != 'index' and name != 'presidents-message'] | system-symlink[name != '']"/>
</xsl:template>
   
<xsl:template match="system-folder[display-name != ''] | system-page[display-name != '' and name != 'index' and name != 'presidents-message'] | system-symlink[name != '']" mode="top-level">
    <xsl:param name="root-folder"/>
        <h2 class="contentsArticleTitle col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <a>
                <xsl:choose>
                    <xsl:when test="name(.) = 'system-symlink'">
                        <xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>
                        <xsl:attribute name="title"><xsl:value-of select="name"/></xsl:attribute>
                        <xsl:value-of select="name"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="href">
                            <xsl:value-of select="path"/>
                            <xsl:if test="name(.)='system-folder'">/<xsl:value-of select="$default-page-name"/></xsl:if>
                        </xsl:attribute>
                        <xsl:attribute name="title"><xsl:value-of select="display-name"/></xsl:attribute>
                        <xsl:value-of select="display-name"/>
                    </xsl:otherwise>
                </xsl:choose>
            </a>
        </h2>
<xsl:for-each select="descendant::system-page[name!='index' and name != 'presidents-message' and display-name != ''] | descendant::system-symlink[name!='']">

            <div class="contentsArticleSection pos1 col-lg-6 col-md-6 col-sm-6 col-xs-12">
                <xsl:if test="position() mod 2 = 0"><xsl:attribute name="class">contentsArticleSection pos2 col-lg-5 col-md-5 col-sm-5 col-xs-12</xsl:attribute></xsl:if>
                <div class="contentsArticleContent">
                <xsl:if test="not(contains(display-name, 'A Message from the President'))">
                <a>
                    <xsl:choose>
                        <xsl:when test="name(.) = 'system-symlink'">
                            <xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>
                            <xsl:attribute name="title"><xsl:value-of select="name"/></xsl:attribute>
                            <xsl:value-of select="name"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:attribute name="href">
                                <xsl:value-of select="path"/>
                            </xsl:attribute>
                            <xsl:attribute name="title"><xsl:value-of select="display-name"/></xsl:attribute>
                            <xsl:value-of select="display-name"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </a>
                </xsl:if>
                </div>
            </div>
        </xsl:for-each>
    
</xsl:template>

</xsl:stylesheet>
  1. 1 Posted by Ryan Griffith on 15 Sep, 2015 01:30 PM

    Ryan Griffith's Avatar

    Hi Matthew,

    I didn't have a chance to test any of this out, but perhaps what you can do is replace the <xsl:for-each> with an <xsl:apply-templates> and create two new templates, one for this new folder and one to output those pages and symlinks (ie the current code within the loop.

    In theory, something like the following:

    <xsl:template match="system-folder[display-name != ''] | system-page[display-name != '' and name != 'index' and name != 'presidents-message'] | system-symlink[name != '']" mode="top-level">
        <xsl:param name="root-folder"/>
        <h2 class="contentsArticleTitle col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <a>
                <xsl:choose>
                    <xsl:when test="name(.) = 'system-symlink'">
                        <xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>
                        <xsl:attribute name="title"><xsl:value-of select="name"/></xsl:attribute>
                        <xsl:value-of select="name"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="href">
                            <xsl:value-of select="path"/>
                            <xsl:if test="name(.)='system-folder'">/<xsl:value-of select="$default-page-name"/></xsl:if>
                        </xsl:attribute>
                        <xsl:attribute name="title"><xsl:value-of select="display-name"/></xsl:attribute>
                        <xsl:value-of select="display-name"/>
                    </xsl:otherwise>
                </xsl:choose>
            </a>
        </h2>
        <xsl:apply-templates select="descendant::system-folder[display-name != ''] | descendant::system-page[name!='index' and name != 'presidents-message' and display-name != ''] | descendant::system-symlink[name!='']" mode="sub-level"/>
    </xsl:template>
    
    <xsl:template match="system-folder[display-name != '']" mode="sub-level">
        ... Output custom stuff here ...
    </xsl:template>
    
    <xsl:template match="system-page[name!='index' and name != 'presidents-message' and display-name != ''] | system-symlink[name!='']" mode="sub-level">
        <div class="contentsArticleSection pos1 col-lg-6 col-md-6 col-sm-6 col-xs-12">
            <xsl:if test="position() mod 2 = 0"><xsl:attribute name="class">contentsArticleSection pos2 col-lg-5 col-md-5 col-sm-5 col-xs-12</xsl:attribute></xsl:if>
            <div class="contentsArticleContent">
            <xsl:if test="not(contains(display-name, 'A Message from the President'))">
            <a>
                <xsl:choose>
                    <xsl:when test="name(.) = 'system-symlink'">
                        <xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>
                        <xsl:attribute name="title"><xsl:value-of select="name"/></xsl:attribute>
                        <xsl:value-of select="name"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="href">
                            <xsl:value-of select="path"/>
                        </xsl:attribute>
                        <xsl:attribute name="title"><xsl:value-of select="display-name"/></xsl:attribute>
                        <xsl:value-of select="display-name"/>
                    </xsl:otherwise>
                </xsl:choose>
            </a>
            </xsl:if>
            </div>
        </div>
    </xsl:template>
    
  2. Ryan Griffith closed this discussion on 24 Sep, 2015 12:46 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac