Copied to clipboard

Flag this post as spam?

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


  • Eric Anatas 10 posts 30 karma points
    Nov 29, 2010 @ 23:13
    Eric Anatas
    0

    Do Umbraco XLST templates always have to be based off $currentPage?

    I'm trying to setup a top navigation bar on my Umbraco site using version 4.5.2. My site structure looks something like this


    Content
         Home
         Resume
         Portfolio
               School
               Job 1
               Job 2
         Activities
         Projects
              Project 1
              Project 2
         Contact

    Now I want a Top navigation bar that lists the following regardless of what page or page level the user is at.


    Home| Resume | Portfolio | Activities | Projects | Contact


    Most of the examples I've seen for navigation bars use a for-each statement like the one shown below.

    <xsl:template match="/">

    <ul>
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:for-each>
    </ul>

    </xsl:template>


    I want to show *all* the level 1 documents (Home, Resume, Portfolio etc..). Yet if I set @level = 1 the XLST above shows the children of the level 1 ancestor of the current page. Which makes sense because that's what this XLST above should do:

    <!-- Front the current page find the ancestor (or self) that has a level = 1
    $currentPage/ancestor-or-self::* [@level=$level]

    <!--Find all children of the level 1 ancestor that are a doc and not hidden-->
    /* [@isDoc and string(umbracoNaviHide) != '1']

    So what I found is that I can then find the parent of the level 1 ancestor of the current page, and then find all the children of that parent and then get all the level 1 documents.

    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/parent::*/* [@isDoc and string(umbracoNaviHide) != '1']">


    This, however, seems like an incredibly round about way of accessing all the level 1 documents. Can I instead write a XPath query based of the root of the entire site rather then the $currentPage?

    Also, is there someway to download the XML for an entire site or at least a the current page so I can have a better understanding of what the XLST I'm writing is working on?

  • Barry Fogarty 493 posts 1129 karma points
    Dec 01, 2010 @ 04:16
    Barry Fogarty
    0

    Eric,

    You can access the root xml node using

    $currentPage/ancestor::root/node

    so a for-each that would select each child of the root node would be something like

    <xsl:for-each select="$currentPage/ancestor::root/node/node">

    BTW I havent tried that out myself so let me know if how it works out.

     

    Re downloading the XML - if you look in the Umbraco.config file (App_Data) that shows you the XML that any XSLT macros will be dealing with.


  • 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