Copied to clipboard

Flag this post as spam?

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


  • Fredrik 89 posts 108 karma points
    Oct 25, 2010 @ 13:20
    Fredrik
    0

    get parent node

    I am iteratiing through all nodes in my content like this:

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

    I need to be able to show the parent node of say:

    Products

         Product category 1

                Product

     

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

      <xsl:if test="highlight = 1">

    I need to put code here to show the parent node of the nodes included by the if-statement

     

      </xsl:if>

     

    I have seen other threads about this but no luck for me so far :)

     

     

  • Rich Green 2246 posts 4008 karma points
    Oct 25, 2010 @ 13:41
    Rich Green
    0

    This page should help you out http://our.umbraco.org/wiki/reference/xslt/xpath-axes-and-their-shortcuts

    Here's what you;re asking for I think

    <xsl:for-each select="$currentPage/descendant::* [@isDoc and string(umbracoNaviHide) != '1']">
    
      <xsl:if test="./parent::node/highlight = 1">
    Show some nodes </xsl:if>

    the "." gets a reference to the current node and /parent::node/ gets the parent node.

    But actually if you want to *only* get the highlighted values you could do filter that in the XPath directly

    Rich 

  • Fredrik 89 posts 108 karma points
    Oct 25, 2010 @ 14:10
    Fredrik
    0

    Maybe I was a little confusing..I want to show the parent of the current node caught in the if-statement

     

    So if product1 is caught in the if-statement - I wish to show what productcategory product1 belongs to

     

    Great page by the way.

  • Rich Green 2246 posts 4008 karma points
    Oct 25, 2010 @ 14:13
    Rich Green
    0

    Like this?

    <xsl:for-each select="$currentPage/descendant::* [@isDoc and string(umbracoNaviHide) != '1']">
    
      <xsl:if test="highlight = 1">
    
           <xsl:value-of select="./parent::node/@nodeName"/>
      </xsl:if>
    </xsl:for-each>

     

  • Fredrik 89 posts 108 karma points
    Oct 25, 2010 @ 14:16
    Fredrik
    0

    Just like that.

    Only problem is that it finds no parent node :) Atleast it shows no output!

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 26, 2010 @ 08:19
    Kasper Dyrvig
    0

    It might work if you do it like

    <xsl:value-of select="umbraco.library:GetXmlNodeById(./@parentID)/@nodeName"/>

     

    - Webspas

Please Sign in or register to post replies

Write your reply to:

Draft