tag:help-archives.hannonhill.com,2010-02-09:/discussions/xslt-formats/5948-need-to-select-folder-for-navigation-codeCascade CMS: Discussion 2015-06-05T18:35:45Ztag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-07T14:01:10Z2015-04-07T14:01:10ZNeed to select folder for navigation code<div><p>Hi Karen,</p>
<p>It looks like the issue is with the
<code>substring-before</code>, which would always return the top
level folder since that is the first string before the
<code>/</code>.</p>
<p>I think your best bet would be to split the page's path up using
<code>/</code> as a delimiter, reverse the order, and loop over
each part to output the corresponding block. If the block is not
found, it will simply be skipped.</p>
<p>Below is a Format I was working on that should accomplish this.
One thing it assumes; however, is that you want to output all
blocks found and not stop on the first one found. Let me know if
this is something you need to add in.</p>
<pre>
<code><?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:str="http://exslt.org/strings" extension-element-prefixes="str">
<xsl:variable name="xhtml-blocks" select="/system-index-block/system-block"/>
<xsl:template match="/system-index-block">
<xsl:variable name="path">
<xsl:value-of select="substring-before(calling-page/system-page/path, calling-page/system-page/name)"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$path = '/'">
<xsl:apply-templates select="system-block[name='index']/block-xhtml"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="str:split($path, '/')" mode="xhtml-block-name">
<!-- Reverse the order -->
<xsl:sort select="position()" data-type="number" order="descending"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="token" mode="xhtml-block-name">
<xsl:apply-templates select="$xhtml-blocks[name = .]/block-xhtml"/>
</xsl:template>
</xsl:stylesheet></code>
</pre>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-07T19:30:28Z2015-04-07T19:30:28ZNeed to select folder for navigation code<div><p>Regarding the last paragraph below. If all of our block names
are unique, there shouldn’t ever be a situation where there
is more than one found unless it will find all parent folders. The
top level parent folder will be used when a subfolder doesn’t
have a corresponding block.</p>
<p>I’ve attached the modified xslt including the code that
formats the left navigation and the xml. It’s not working.
There is no left navigation appearing on any pages after these
changes were made.</p>
<p>Here is an actual example. The top level folder
“ace” contains multiple pages and subfolders. The block
named “ace” will be used for all the left navigation
except for the subfolder “ace/compsci”. All pages
within “ace/compsci” will use the block named
“compsci”. There are additional subfolders
“ace/moonbuggy” and “ace/nasa” but the
pages within these folders will use the “ace” block
since there are no matching “moonbuggy” or
“nasa” blocks. I hope that makes sense.</p>
<p>We do have situations where there might be a 3rd or 4th level
folder that might have a matching block so the xslt will need to
work no matter what level the folder is.</p>
<p>What do I need to change? Thank you very much!</p>
<p>Karen Wilson<br>
Web Designer<br>
Southwestern Oklahoma State University<br>
(580) 774-6147 <a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a><a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a></p></div>karen.wilsontag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-08T15:13:08Z2015-04-08T15:13:08ZNeed to select folder for navigation code<div><p>I have an idea. Would it be easier if we named our subfolder
similar to the path? Example: ace-compsci so the compsci subfolder
would use the left navigation block named ace-compsci since the
path the that folder is ace/compsci.</p>
<p>Karen Wilson<br>
Web Designer<br>
Southwestern Oklahoma State University<br>
(580) 774-6147 <a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a><a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a></p></div>karen.wilsontag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-08T15:22:56Z2015-04-08T15:22:56ZNeed to select folder for navigation code<div><p>Hi Karen,</p>
<p>That could work. So would the idea be to look for the associated
block and if one is not found fall back to another block?</p>
<p>Another idea I had would be to place the block within the
folders themselves and use a contextual Index Block that would
return the Blocks at each folder level (if one is present). Using
this Index Block, you would traverse up the folder hierarchy until
you find an XHTML Block. This is very similar to how we implement
setup blocks. The benefit of this route is:</p>
<ul>
<li>Your Index Block only includes the necessary XHTML Blocks based
on the calling page, not all Blocks within the Site</li>
<li>You do not need to rely on a specific naming scheme for the
Blocks</li>
<li>The Blocks can live in the same folders as the Pages</li>
<li>You have a more consistent way of Pages inheriting Blocks from
their parent folder(s)</li>
</ul>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-08T15:25:53Z2015-04-08T15:25:53ZNeed to select folder for navigation code<div><p>If we used your suggestion, would that mean that if there
isn’t a folder/block combination the xslt would use the top
level parent folder?</p>
<p>Karen Wilson<br>
Web Designer<br>
Southwestern Oklahoma State University<br>
(580) 774-6147 <a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a><a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a></p></div>karen.wilsontag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-08T18:54:50Z2015-04-08T18:54:50ZNeed to select folder for navigation code<div><p>Correct, the Format would continue to traverse up the folder
structure until it finds a parent folder containing a valid
Block.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-08T18:56:39Z2015-04-08T18:56:39ZNeed to select folder for navigation code<div><p>I’ll change these but will take a couple of days before I
have them all ready to go as I’m working in between other
projects. At that time, I’m sure I’ll have more
questions. Thanks.</p>
<p>Karen Wilson<br>
Web Designer<br>
Southwestern Oklahoma State University<br>
(580) 774-6147 <a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a><a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a></p></div>karen.wilsontag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-08T19:17:13Z2015-04-08T19:17:13ZNeed to select folder for navigation code<div><p>Not a problem at all, Karen. Please keep me posted and let me
know if you have any questions reworking the setup.</p>
<p>Have a great day!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-10T16:50:25Z2015-04-10T16:50:25ZNeed to select folder for navigation code<div><p>I’ve created the folder structure and placed the blocks
where they need to go. I don’t know if it matters or not but
all the blocks are now named “leftnav”. I’m not
sure how the index block needs to be set up as well as what the
xslt would look like. Do you have an example I could look at?</p>
<p>Karen Wilson<br>
Web Designer<br>
Southwestern Oklahoma State University<br>
(580) 774-6147 <a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a><a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a></p></div>karen.wilsontag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-16T18:22:21Z2015-04-16T18:22:21ZNeed to select folder for navigation code<div><p>Ryan,</p>
<p>I’ve tried several things but not having much luck. It
makes perfect sense as far as logic goes but I’m not sure how
I need to set up the index block to make things work. Can you tell
me what options I need to select for the index block so that it
finds the left navigation block in the folder?</p>
<p>Karen Wilson<br>
Web Designer<br>
Southwestern Oklahoma State University<br>
(580) 774-6147 <a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a><a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a></p></div>karen.wilsontag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-17T13:50:52Z2015-04-17T13:50:52ZNeed to select folder for navigation code<div><p>Hi Karen,</p>
<p>It sounds as though you are on the right track. Using a
consistent name for each block is definitely ideal in-case you ever
have other blocks in those folders.</p>
<p>I am attaching a screenshot of the Index Block setup that should
provide what you need. Below I have provided sample XSLT that will
output the contents of the XHTML Block located closest to the
calling page. Specifically, if one is not found in the current
folder, the block within an ancestor folder will be used:</p>
<pre>
<code><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" extension-element-prefixes="str" version="1.0" xmlns:str="http://exslt.org/strings">
<xsl:template match="/system-index-block">
<xsl:apply-templates select="//system-block[name = 'leftnav']">
<xsl:sort order="descending" select="path"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="system-block">
<xsl:if test="position() = last()">
<xsl:copy-of select="block-xhtml/node()"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet></code>
</pre>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-17T14:41:31Z2015-04-17T14:41:31ZNeed to select folder for navigation code<div><p>You're the best! I'll give this a try. Have a good weekend.</p>
<p>Karen Wilson</p></div>karen.wilsontag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-17T14:53:48Z2015-04-17T14:53:48ZNeed to select folder for navigation code<div><p>You too, Karen. Please keep me posted on how you make out with
the updated Format.</p>
<p>Have a good one!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-21T14:15:39Z2015-04-21T14:15:39ZNeed to select folder for navigation code<div><p>I haven’t had a chance to work on this as I have been out
of state at a conference. I hopefully will get to this later today
or tomorrow.</p>
<p>Karen Wilson<br>
Web Designer<br>
Southwestern Oklahoma State University<br>
(580) 774-6147 <a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a><a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a></p></div>karen.wilsontag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-24T16:01:17Z2015-04-24T16:01:17ZNeed to select folder for navigation code<div><p>I just got a chance to finish up on this. Everything worked
perfectly! I appreciate your help.</p>
<p>Karen Wilson<br>
Web Designer<br>
Southwestern Oklahoma State University<br>
(580) 774-6147 <a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a><a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a></p></div>karen.wilsontag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-24T16:06:07Z2015-04-24T16:06:07ZNeed to select folder for navigation code<div><p>Thank you for following up, Karen. I am glad to hear the
proposed changes did the trick for you.</p>
<p>I'm going to go ahead and close this discussion, please feel
free to comment or reply to re-open if you have any additional
questions.</p>
<p>Have a great day!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-29T20:59:18Z2015-04-29T20:59:18ZNeed to select folder for navigation code<div><p>I thought things were working properly but I’m having
trouble with the subfolders left navigation working. I’ve
attached two screenshots. The format.jpg shows that I have the
left-nav xslt open and have the block and page selected. The Format
Result shows the correct navigation. When I preview the page
normally it uses the leftnav block from its parent folder though. I
don’t know that it matters or not but it is more than a
single level down from the parent.</p>
<p>Example: /him/programs/undergraduate/index</p>
<p>In the example above, the “programs” folder has a
leftnav block and then the “undergraduate” folder has a
leftnav block. It doesn’t view properly. I tested to see if I
had a leftnav block in the “programs” folder and a test
page in it as well but it still didn’t use the right
block.</p>
<p>Example: /ace/compsci/index</p>
<p>In this example, the “ace” and “compsci”
folders both contain a leftnav block. The pages in compsci all
display the right left naviation.</p>
<p>I have no idea why it’s inconsistent in the way it’s
working. Any idea that I should try?</p>
<p>Karen Wilson<br>
Web Designer<br>
Southwestern Oklahoma State University<br>
(580) 774-6147 <a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a><a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a></p></div>karen.wilsontag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-30T13:05:21Z2015-04-30T13:05:21ZNeed to select folder for navigation code<div><p>Hi Karen,</p>
<p>I am sorry to hear the Format is not working out for you.</p>
<p>When you have a moment, please attach the Format to this
discussion along with sample XML obtained when previewing the
<strong>/him/programs/undergraduate/index</strong> page and
appropriate XML so I can take a closer look.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-04-30T13:34:40Z2015-04-30T13:34:40ZNeed to select folder for navigation code<div><p>Let me know if I don’t have the right stuff attached.
Thank you.</p>
<p>Him-programs-undergraduate-index-xml.txt</p>
<p>· This was taking when editing the left-nav format and
preview options of _internal/blocks/redesign/index-left-nav and
page him/programs/undergraduate/index<br>
Left-nav-xslt.txt</p>
<p>· Format<br>
Him-programs-undergraduate-index.txt</p>
<p>· I have an XML output on the page
him/programs/undergraduate/index and this is the xml for the
page</p>
<p>Karen Wilson<br>
Web Designer<br>
Southwestern Oklahoma State University<br>
(580) 774-6147 <a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a><a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a></p></div>karen.wilsontag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-05-01T20:40:19Z2015-05-01T20:40:19ZNeed to select folder for navigation code<div><p>I didn’t hear anything from you yesterday so wanted to
make sure you received this email. I don’t need to get this
resolved until next week sometime but wanted to make sure you at
least had it. Have a good weekend!</p>
<p>Karen Wilson<br>
Web Designer<br>
Southwestern Oklahoma State University<br>
(580) 774-6147 <a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a><a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a></p>
<p>From: Wilson, Karen<br>
Sent: Thursday, April 30, 2015 7:34 AM<br>
To: 'Ryan Griffith'<br>
Subject: RE: Need to select folder for navigation code [XSLT
Formats #5948]</p>
<p>Let me know if I don’t have the right stuff attached.
Thank you.</p>
<p>Him-programs-undergraduate-index-xml.txt</p>
<p>· This was taking when editing the left-nav format and
preview options of _internal/blocks/redesign/index-left-nav and
page him/programs/undergraduate/index<br>
Left-nav-xslt.txt</p>
<p>· Format<br>
Him-programs-undergraduate-index.txt</p>
<p>· I have an XML output on the page
him/programs/undergraduate/index and this is the xml for the
page</p>
<p>Karen Wilson<br>
Web Designer<br>
Southwestern Oklahoma State University<br>
(580) 774-6147 <a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a><a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a></p></div>karen.wilsontag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-05-01T20:52:24Z2015-05-01T20:52:24ZNeed to select folder for navigation code<div><p>HI Karen,</p>
<p>My apologies for not responding sooner. Unfortunately, I did not
have a chance to take a look at your Format yet, but I will be in
touch as soon as I have a chance to look things over and gather
some additional information for you.</p>
<p>Have a great day!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-05-11T20:21:54Z2015-05-11T20:21:54ZNeed to select folder for navigation code<div><p>Hi Karen,</p>
<p>My apologies for the delayed response to your discussion.</p>
<p>After some local testing, it definitely looks like the order of
the blocks is the opposite of what I was seeing in during my
original testing. Curious, but try adjusting the following
line:</p>
<pre>
<code><xsl:sort order="descending" select="path"/></code>
</pre>
<p>To:</p>
<pre>
<code><xsl:sort order="ascending" select="path"/></code>
</pre>
<p>And let me know if this resolves the issue you are
encountering.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-05-11T20:31:29Z2015-05-11T20:31:29ZNeed to select folder for navigation code<div><p>Works like a charm! Thanks.</p>
<p>Karen Wilson<br>
Web Designer<br>
Southwestern Oklahoma State University<br>
(580) 774-6147 <a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a><a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a></p></div>karen.wilsontag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-05-12T13:50:15Z2015-05-12T13:50:15ZNeed to select folder for navigation code<div><p>Thank you for following up, Karen. I am glad to hear the
adjustment did the trick.</p>
<p>I'm going to go ahead and close this discussion, please feel
free to comment or reply to re-open if you have any additional
questions.</p>
<p>Have a great day!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-05-18T17:49:30Z2015-05-18T17:49:30ZNeed to select folder for navigation code<div><p>I thought this was resolved; however, it fixed a set of left
navigation items in folders where the “descending”
wasn’t working. I went back to verify left navigations
previously done and the ones where the “descending was
working is now not working. Why would folders act differently?</p>
<p>Karen Wilson<br>
Web Designer<br>
Southwestern Oklahoma State University<br>
(580) 774-6147 <a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a><a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a></p></div>karen.wilsontag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-06-02T16:28:16Z2015-06-02T16:28:16ZNeed to select folder for navigation code<div><p>Hi Karen,</p>
<p>My apologies for the delayed response to your discussion. Were
you able to narrow down the cause of the ordering issue?</p>
<p>Off-hand I am not entirely sure why certain folders would behave
differently since we're sorting by path regardless. If you are able
to provide a couple of examples of folders that are working and not
working, I'd be happy to log into your instance to try taking a
closer look.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-06-05T13:22:46Z2015-06-05T13:22:46ZNeed to select folder for navigation code<div><p>I’ve checked the folders over again and they all seem to
be working now. Thank you for checking on this.</p>
<p>Karen Wilson<br>
Web Designer<br>
Southwestern Oklahoma State University<br>
(580) 774-6147 <a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a><a href="mailto:karen.wilson@swosu.edu">karen.wilson@swosu.edu</a></p></div>karen.wilsontag:help-archives.hannonhill.com,2010-02-09:Comment/365025072015-06-05T18:35:44Z2015-06-05T18:35:44ZNeed to select folder for navigation code<div><p>Thank you for following up, Karen. I am glad to hear the Format
appears to be working.</p>
<p>I'm going to go ahead and close this discussion, please feel
free to comment or reply to re-open if you have any additional
questions or issues.</p>
<p>Have a great day!</p></div>Ryan Griffith