Styling subfolders in a table of contents page
We have a site that generates a table of contents based on the folder structure. So each of the section (i.e. On the Commons, Alumni Profiles, Athletics) are folders within the main folder for each issue of this publication.
Lately we've been having a lot of On the Commons articles and I was wondering if there was a way to split up the articles within this folder? My idea was to create subfolders under On the Commons and style it a bit differently. Is there a way to do this?
This is the format used for the page
<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">
<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="system-page[name!='index' and name != 'presidents-message' and display-name != ''] | system-symlink[name!='']">
<div class="contentsArticleSection pos1">
<xsl:if test="position() mod 2 = 0"><xsl:attribute name="class">contentsArticleSection pos2</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>
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
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
1 Posted by Ryan Griffith on 18 Mar, 2015 07:05 PM
Hi Matthew,
IMO, I think you should switch over that
<xsl:for-each>
to a,<xsl:apply-templates>
and create new templates to handle your pages and links (which would be the same content within the loop now) and these subfolders (which would essentially call the same<xsl:apply-templates>
.Alternatively, you might be able to tweak the XPath in your
<xsl:for-each>
to look for these pages and links at any level. I think something like the following might work:So with
.//
, it will start at the current top-level folder and look at any level within it's descendants.Another way to write this would be to use the descendant axis:
Please let me know if you have any questions.
Thanks!
Ryan Griffith closed this discussion on 08 Apr, 2015 02:30 PM.