Copied to clipboard

Flag this post as spam?

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


  • Geoff Baldwin 80 posts 100 karma points
    Oct 08, 2010 @ 13:33
    Geoff Baldwin
    0

    Addressing a specific node in a for each select= statement

    Hi

    I am very new to Umbraco and xslt and am on the very steep bit of my earning curve!

    Using Umbraco 4.5.2 I have modified (with a lot of help from Dirk on here) a standard runway xslt file to provide me with a thumnail link to each sub gallery in the node gallery in the structure below when navigating to Galleries:

    Home page
      Node1
      Node2
      Node3
      Galleries
          Gallery1
          Gallery2

    The ror each statement is  <xsl:for-each select="$currentPage/* [@isDoc]">

    I'd like to use the concept in a more general sense as a sort of menu in another site I am about to build so that I can include the macro in a master page so that in a structure like:

    Home Page
      About Us
      Service1
      Service2

    I can get a thumbnail for each of the nodes.

    To see if I could emulate the success of <xsl:for-each select="$currentPage/* [@isDoc]"> but using a specific node name I have experimented in my current site (top example) using:

     <xsl:for-each select="Galleries/* [@isDoc]">

     <xsl:for-each select="../Galleries/* [@isDoc]">

     <xsl:for-each select="./Galleries/* [@isDoc]">

    Whilst not giving errors none display the thumbnails.

    So,

    1. can I address a specific node?

    2. can I just use $root to address "Home Page"

     

     

  • Ernst Utvik 123 posts 235 karma points
    Oct 08, 2010 @ 13:50
    Ernst Utvik
    0

    First you have to find your root node:

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

    Then you can list the children with something like this:

    <xsl:for-each select="$rootNode/child::* [@isDoc][not(umbracoNaviHide = 1)]">

    <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>

    </xsl:for-each>

    The umbracoNaviHide is useful if you have a node that you do not want to show in the navigation. Just add true/false property in the doc type.

  • Geoff Baldwin 80 posts 100 karma points
    Oct 08, 2010 @ 14:26
    Geoff Baldwin
    0

    Thanks Ernst - works a treat.

    If I want to start from, say the Galleries subnode, how would I modify the xsl:variable statement?

    I guessed at adding /Galleries after self::* , and instead of *  :):) but no luck!

  • Ernst Utvik 123 posts 235 karma points
    Oct 08, 2010 @ 14:51
    Ernst Utvik
    0

    No problem Geoff :)

    If the Galleries subnode has a nodetype different from its siblings you can find it by its nodetype alias:

    <xsl:variable name="galleriesNode" select="$rootNode/child::Galleries [@isDoc]"/>

    If the nodes use the same nodetype, you can get the gallery node by its id:

    <xsl:variable name="galleriesNode" select="$rootNode/child::* [@isDoc and @id = IDOFYOURNODE]"/>

    You can also get it by its name:

    <xsl:variable name="galleriesNode" select="$rootNode/child::* [@isDoc and @nodeName = 'NODENAME']"/>

  • Geoff Baldwin 80 posts 100 karma points
    Oct 08, 2010 @ 21:55
    Geoff Baldwin
    0

    Once again Ernst - thank you..

    Both for the solution and the mini xsl lesson!

Please Sign in or register to post replies

Write your reply to:

Draft