Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Roger 195 posts 474 karma points
    Oct 01, 2012 @ 13:16
    Roger
    0

    Help with XSLT to display content on all levels

    Hi all,

    I have a sidebar control where the user can add blocks to the sidebar with a heading and text.
    The sidebars show on the homepage but not on internal text pages. I think this is something to do with the level set in the XSLT but im not sure. Please can you help?
    Here is a breakdown of what I have:

    The XSLT:

    <xsl:variable name="sidebarNode" select="$currentPage/parent::*/child::*[@level=1]"/>

          <xsl:for-each select="$sidebarNode/child::Sidebars">
              <div class="hotspot">   
                      <h4><xsl:value-of select="sidebarHeading" disable-output-escaping="yes"/></h4>
                <img width="52" height="52" src="/images/icons/dezinerfolio/info.png" />
                      <xsl:value-of select="sidebarContent" disable-output-escaping="yes"/>
              </div>
          </xsl:for-each>

    The content structure:

    As I mentioned, the sidebars show on the homepage (Stella Maris node) but not on the internal pages

    Any help is greatly appreciated

    Thanks

    Roger

  • Roger 195 posts 474 karma points
    Oct 01, 2012 @ 13:19
    Roger
    0

    To add: The Macro is in the Master Template

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Oct 01, 2012 @ 13:40
    Chriztian Steinmeier
    0

    Hi Roger,

    You should be able to always locate the right nodes using something like this:

    <!-- Find the "Stella Maris" node from any descendant -->
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
    <!-- Locate "Sidebar Control" folder -->
    <xsl:variable name="sidebarNode" select="$siteRoot/../SidebarControl" /><!-- Use the actual doctype alias -->
    
    <xsl:for-each select="$sidebarNode/Sidebars">
        <div class="hotspot">
            <h4><xsl:value-of select="sidebarHeading" disable-output-escaping="yes" /></h4>
            <img width="52" height="52" src="/images/icons/dezinerfolio/info.png" />
            <xsl:value-of select="sidebarContent" disable-output-escaping="yes" />
        </div>
    </xsl:for-each>
    

    /Chriztian

  • Roger 195 posts 474 karma points
    Oct 01, 2012 @ 14:06
    Roger
    0

    Hi Chriztian,

    That didnt work unfortunately. No errors but the sidebars disappeared from the homepage.

    Its just a development site at the moment so Im happy to give login details

    Thank you very much for the help

    Roger

  • Roger 195 posts 474 karma points
    Oct 01, 2012 @ 14:07
    Roger
    0

    Ah, i think I have it working.

    I used my code but changed the variable to:

    <xsl:variable name="sidebarNode" select="$currentPage/ancestor-or-self::*/child::*[@level=1]"/>

    instead of

    <xsl:variable name="sidebarNode" select="$currentPage/parent::*/child::*[@level=1]"/>

    Many thanks :)

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Oct 01, 2012 @ 14:32
    Chriztian Steinmeier
    0

    Hi Roger,

    Did you use the actual doctype alias for the SidebarControl?

    The thing is, your sidebarNode variable actually selects all the level 1 nodes ("Stella Maris", "Sidebar Control" & "Slider Control") because the selector goes through currentPage and all its ancestors, selecting all of their children, then filtering by the level attribute.

    The only reason the for-each grabs the right nodes is because you have no Sidebars documents as children of neither "Stella Maris" nor "Slider Control"...

    It's not a big problem in this setup - but you're very likely to refer to this for another site maybe, and if you're on a big site, those kinds of selectors can get very slow and have sideeffects because of the amount of nodes that are really selected.

    /Chriztian

  • Roger 195 posts 474 karma points
    Oct 01, 2012 @ 14:39
    Roger
    0

    Ah I see, that makes sense.

    I'll give that a go and see if it works

    Many thanks for all the help

    Roger

  • Roger 195 posts 474 karma points
    Oct 01, 2012 @ 14:54
    Roger
    0

    Hi chriztian,

    I tried that but the sidebars failed to display on all pages again,

    This code works:

     <xsl:variable name="sidebarNode" select="$currentPage/ancestor-or-self::*/child::*[@level=1]"/>
          <xsl:for-each select="$sidebarNode/child::Sidebars">
              <div class="hotspot">
                      <h4><xsl:value-of select="sidebarHeading" disable-output-escaping="yes"/></h4>
                <img width="52" height="52" src="/images/icons/dezinerfolio/info.png" />
                      <xsl:value-of select="sidebarContent" disable-output-escaping="yes"/>
              </div>
          </xsl:for-each>

    Am i doing something wrong I wonder?

    Roger

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies