Copied to clipboard

Flag this post as spam?

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


  • kukuwka 75 posts 96 karma points
    Aug 08, 2010 @ 16:39
    kukuwka
    0

    Get root of current content

    Hi,

    I have 2 contents.

    I want to get root node ( parentID="-1" level="1" ) of content that I'm in it now.

    If I write:

    //ancestor::node[@parentID= -1]

    I receive two roots with parentID="-1" .

    How can I get only one root of current content?

    Thanks

     

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 08, 2010 @ 17:35
    Matt Brailsford
    0

    Hi Kukuwka,

    It sounds like something has gone wrong in your installation, as you should only have one root "Content" node. You'll then create one or more site roots under this node.

    To get at the root node, you'll want to use $currentNode/ancestor-or-self::root, but as I say, if you've got 2 nodes, something isn't quite right.

    Matt

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 08, 2010 @ 18:40
    Chriztian Steinmeier
    0

    Hi kukuwka,

    It looks like you're accidentally supplying the wrong context (or none) to your XPath expression - if you're inside a for-each statement and you use the above expression, you're asking for ALL node elements with the parentID -1, if that's your scenario, you'll just need to supply $currentPage as context - like this:

    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::node[@parentID = -1]" />

    /Chriztian 

  • kukuwka 75 posts 96 karma points
    Aug 09, 2010 @ 07:44
    kukuwka
    0

    I want to use it in Data Types and not in XSLT Files .

    So "$currentPage" not fit here.

    Thanks.

  • Arjan H. 226 posts 463 karma points c-trib
    Aug 09, 2010 @ 08:47
    Arjan H.
    0

    So you're declaring some kind of datatype and you're using some XPATH to set the parent node ID, am I right? If that's the case you should be able to use $currentPage like you would in XSLT.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Aug 09, 2010 @ 11:03
    Thomas Höhler
    0

    In principle you can select the root of any xml file via

    acestor-or-self::root

     

    and if you don't have the currentPage variable you can select it via

    Snippet

    umbraco.library.GetXmlAll()

    So you can select the root of the content nodes via

    <xsl:variable name="siteRoot" select="umbraco.library.GetXmlAll()/ancestor-or-self::root" />

    hth, Thomas

  • kukuwka 75 posts 96 karma points
    Aug 11, 2010 @ 17:02
    kukuwka
    0

    If I use:

    string Xpath = "$currentPage/ancestor-or-self::node[@parentID = -1]"; iterator=library.GetXmlNodeByXPath(Xpath));

    I get:

     Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.

     

    How can I solve it?

    kukuwka.

Please Sign in or register to post replies

Write your reply to:

Draft