Need to select folder for navigation code

karen.wilson's Avatar

karen.wilson

06 Apr, 2015 08:40 PM

I have created an xhtml block named identically to the folder in which I need the block used. Example: folder name is "ace" and the xhtml block containing the code for the left navigation is "ace" as well. There is an index block that collects all of the xhtml blocks. The attached file is part of the xslt that is used to select which part of the index block to use.

My problem is that it always goes back to the first level folders. There are some instances that I need to create an xhtml block for a subfolder that will be used for the pages included in that subfolder. Example: folder name is "/ace/nasa" and the xhtml block is named "nasa". All xhtml blocks and folder names are unique.

I need to modify the xslt so that if there is a block identically named to a subfolder, that code from the block matching that name will be used instead of the first level block.

  1. 1 Posted by Ryan Griffith on 07 Apr, 2015 02:01 PM

    Ryan Griffith's Avatar

    Hi Karen,

    It looks like the issue is with the substring-before, which would always return the top level folder since that is the first string before the /.

    I think your best bet would be to split the page's path up using / 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.

    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.

    <?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>
    

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by karen.wilson on 07 Apr, 2015 07:30 PM

    karen.wilson's Avatar

    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.

    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.

    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.

    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.

    What do I need to change? Thank you very much!

    Karen Wilson
    Web Designer
    Southwestern Oklahoma State University
    (580) 774-6147
    [email blocked]<mailto:[email blocked]>

  3. 3 Posted by karen.wilson on 08 Apr, 2015 03:13 PM

    karen.wilson's Avatar

    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.

    Karen Wilson
    Web Designer
    Southwestern Oklahoma State University
    (580) 774-6147
    [email blocked]<mailto:[email blocked]>

  4. 4 Posted by Ryan Griffith on 08 Apr, 2015 03:22 PM

    Ryan Griffith's Avatar

    Hi Karen,

    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?

    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:

    • Your Index Block only includes the necessary XHTML Blocks based on the calling page, not all Blocks within the Site
    • You do not need to rely on a specific naming scheme for the Blocks
    • The Blocks can live in the same folders as the Pages
    • You have a more consistent way of Pages inheriting Blocks from their parent folder(s)

    Please let me know if you have any questions.

    Thanks!

  5. 5 Posted by karen.wilson on 08 Apr, 2015 03:25 PM

    karen.wilson's Avatar

    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?

    Karen Wilson
    Web Designer
    Southwestern Oklahoma State University
    (580) 774-6147
    [email blocked]<mailto:[email blocked]>

  6. 6 Posted by Ryan Griffith on 08 Apr, 2015 06:54 PM

    Ryan Griffith's Avatar

    Correct, the Format would continue to traverse up the folder structure until it finds a parent folder containing a valid Block.

    Please let me know if you have any questions.

    Thanks!

  7. 7 Posted by karen.wilson on 08 Apr, 2015 06:56 PM

    karen.wilson's Avatar

    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.

    Karen Wilson
    Web Designer
    Southwestern Oklahoma State University
    (580) 774-6147
    [email blocked]<mailto:[email blocked]>

  8. 8 Posted by Ryan Griffith on 08 Apr, 2015 07:17 PM

    Ryan Griffith's Avatar

    Not a problem at all, Karen. Please keep me posted and let me know if you have any questions reworking the setup.

    Have a great day!

  9. 9 Posted by karen.wilson on 10 Apr, 2015 04:50 PM

    karen.wilson's Avatar

    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?

    Karen Wilson
    Web Designer
    Southwestern Oklahoma State University
    (580) 774-6147
    [email blocked]<mailto:[email blocked]>

  10. 10 Posted by karen.wilson on 16 Apr, 2015 06:22 PM

    karen.wilson's Avatar

    Ryan,

    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?

    Karen Wilson
    Web Designer
    Southwestern Oklahoma State University
    (580) 774-6147
    [email blocked]<mailto:[email blocked]>

  11. 11 Posted by Ryan Griffith on 17 Apr, 2015 01:50 PM

    Ryan Griffith's Avatar

    Hi Karen,

    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.

    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:

    <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>
    

    Please let me know if you have any questions.

    Thanks!

  12. 12 Posted by karen.wilson on 17 Apr, 2015 02:41 PM

    karen.wilson's Avatar

    You're the best! I'll give this a try. Have a good weekend.

    Karen Wilson

  13. 13 Posted by Ryan Griffith on 17 Apr, 2015 02:53 PM

    Ryan Griffith's Avatar

    You too, Karen. Please keep me posted on how you make out with the updated Format.

    Have a good one!

  14. 14 Posted by karen.wilson on 21 Apr, 2015 02:15 PM

    karen.wilson's Avatar

    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.

    Karen Wilson
    Web Designer
    Southwestern Oklahoma State University
    (580) 774-6147
    [email blocked]<mailto:[email blocked]>

  15. 15 Posted by karen.wilson on 24 Apr, 2015 04:01 PM

    karen.wilson's Avatar

    I just got a chance to finish up on this. Everything worked perfectly! I appreciate your help.

    Karen Wilson
    Web Designer
    Southwestern Oklahoma State University
    (580) 774-6147
    [email blocked]<mailto:[email blocked]>

  16. 16 Posted by Ryan Griffith on 24 Apr, 2015 04:06 PM

    Ryan Griffith's Avatar

    Thank you for following up, Karen. I am glad to hear the proposed changes did the trick for you.

    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.

    Have a great day!

  17. Ryan Griffith closed this discussion on 24 Apr, 2015 04:06 PM.

  18. karen.wilson re-opened this discussion on 29 Apr, 2015 08:59 PM

  19. 17 Posted by karen.wilson on 29 Apr, 2015 08:59 PM

    karen.wilson's Avatar

    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.

    Example: /him/programs/undergraduate/index

    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.

    Example: /ace/compsci/index

    In this example, the “ace” and “compsci” folders both contain a leftnav block. The pages in compsci all display the right left naviation.

    I have no idea why it’s inconsistent in the way it’s working. Any idea that I should try?

    Karen Wilson
    Web Designer
    Southwestern Oklahoma State University
    (580) 774-6147
    [email blocked]<mailto:[email blocked]>

  20. 18 Posted by Ryan Griffith on 30 Apr, 2015 01:05 PM

    Ryan Griffith's Avatar

    Hi Karen,

    I am sorry to hear the Format is not working out for you.

    When you have a moment, please attach the Format to this discussion along with sample XML obtained when previewing the /him/programs/undergraduate/index page and appropriate XML so I can take a closer look.

    Thanks!

  21. 19 Posted by karen.wilson on 30 Apr, 2015 01:34 PM

    karen.wilson's Avatar

    Let me know if I don’t have the right stuff attached. Thank you.

    Him-programs-undergraduate-index-xml.txt

    · 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
    Left-nav-xslt.txt

    · Format
    Him-programs-undergraduate-index.txt

    · I have an XML output on the page him/programs/undergraduate/index and this is the xml for the page

    Karen Wilson
    Web Designer
    Southwestern Oklahoma State University
    (580) 774-6147
    [email blocked]<mailto:[email blocked]>

  22. 20 Posted by karen.wilson on 01 May, 2015 08:40 PM

    karen.wilson's Avatar

    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!

    Karen Wilson
    Web Designer
    Southwestern Oklahoma State University
    (580) 774-6147
    [email blocked]<mailto:[email blocked]>

    From: Wilson, Karen
    Sent: Thursday, April 30, 2015 7:34 AM
    To: 'Ryan Griffith'
    Subject: RE: Need to select folder for navigation code [XSLT Formats #5948]

    Let me know if I don’t have the right stuff attached. Thank you.

    Him-programs-undergraduate-index-xml.txt

    · 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
    Left-nav-xslt.txt

    · Format
    Him-programs-undergraduate-index.txt

    · I have an XML output on the page him/programs/undergraduate/index and this is the xml for the page

    Karen Wilson
    Web Designer
    Southwestern Oklahoma State University
    (580) 774-6147
    [email blocked]<mailto:[email blocked]>

  23. 21 Posted by Ryan Griffith on 01 May, 2015 08:52 PM

    Ryan Griffith's Avatar

    HI Karen,

    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.

    Have a great day!

  24. 22 Posted by Ryan Griffith on 11 May, 2015 08:21 PM

    Ryan Griffith's Avatar

    Hi Karen,

    My apologies for the delayed response to your discussion.

    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:

    <xsl:sort order="descending" select="path"/>
    

    To:

    <xsl:sort order="ascending" select="path"/>
    

    And let me know if this resolves the issue you are encountering.

    Please let me know if you have any questions.

    Thanks!

  25. 23 Posted by karen.wilson on 11 May, 2015 08:31 PM

    karen.wilson's Avatar

    Works like a charm! Thanks.

    Karen Wilson
    Web Designer
    Southwestern Oklahoma State University
    (580) 774-6147
    [email blocked]<mailto:[email blocked]>

  26. 24 Posted by Ryan Griffith on 12 May, 2015 01:50 PM

    Ryan Griffith's Avatar

    Thank you for following up, Karen. I am glad to hear the adjustment did the trick.

    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.

    Have a great day!

  27. Ryan Griffith closed this discussion on 12 May, 2015 01:50 PM.

  28. karen.wilson re-opened this discussion on 18 May, 2015 05:49 PM

  29. 25 Posted by karen.wilson on 18 May, 2015 05:49 PM

    karen.wilson's Avatar

    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?

    Karen Wilson
    Web Designer
    Southwestern Oklahoma State University
    (580) 774-6147
    [email blocked]<mailto:[email blocked]>

  30. 26 Posted by Ryan Griffith on 02 Jun, 2015 04:28 PM

    Ryan Griffith's Avatar

    Hi Karen,

    My apologies for the delayed response to your discussion. Were you able to narrow down the cause of the ordering issue?

    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.

    Thanks!

  31. 27 Posted by karen.wilson on 05 Jun, 2015 01:22 PM

    karen.wilson's Avatar

    I’ve checked the folders over again and they all seem to be working now. Thank you for checking on this.

    Karen Wilson
    Web Designer
    Southwestern Oklahoma State University
    (580) 774-6147
    [email blocked]<mailto:[email blocked]>

  32. 28 Posted by Ryan Griffith on 05 Jun, 2015 06:35 PM

    Ryan Griffith's Avatar

    Thank you for following up, Karen. I am glad to hear the Format appears to be working.

    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.

    Have a great day!

  33. Ryan Griffith closed this discussion on 05 Jun, 2015 06:35 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