Copied to clipboard

Flag this post as spam?

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


  • Garrett Fisher 341 posts 496 karma points
    Oct 17, 2012 @ 22:34
    Garrett Fisher
    0

    XPath: Get Highest Ancestor of Self Without $currentPage Variable

    Hi,

    I'm using a DataType I created with Tribal Xpath Node Relations (uComponents) and I also have multiple Root ("Home") nodes because I have multilingual sites.  Tricky.  I'm creating a dropdown which lists all Resources (hopefully only under the current site/language!) but I'm having an issue where all the Resource items are being listed once for every language/site (because the original site was copied in its entirety).  The dropdown is so that a user can select which items to list on the given page.

    Obviously, it makes sense that this is happening based on this xpath expression:

    //Resource

    !  I expected this to happen initially.  But when I went in to fix it, I realized I needed an expression that would get documents of type Resource under ONLY the highest parent of the current node.  I can't figure out how to do this withouth the $currentPage variable, or indeed, without even Having a current context.  This is happening in the CMS.  I have tried:

    current()/ancestor-or-self::Home[@isDoc]//Resource
    ancestor-or-self::Home[@isDoc]//Resource
    .ancestor-or-self::Home[@isDoc]//Resource

    Just kind of grabbing at straws here, clearly!  Surely someone has come upon this duplicate situation before and can offer me some advice?  I do NOT want to do something like this:

    //Home[@isDoc and language='English']//Resource

    Because then I would need a separate form control for each site specifying the language.  That would be a lot of work.  And I am a programmer and do not want that ;)  Any ideas?  Possible in pure xpath?

    Thanks,

    Garrett

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 17, 2012 @ 22:47
    Chriztian Steinmeier
    2

    Hi Garrett,

    It's indeed tricky if you don't have *any* context - most of the uComponents "XPath *" pickers allow you to use the variables $currentPage, $parentPage and $ancestorOrSelf (depending on version) to handle these types of situations.

    I found this "secret" on a forum post - you can use $currentNodeId in the XPath, so:

    /root/Home[descendant-or-self::*[@id = $currentNodeId]]//Resource

    or maybe this will even work:

    id($currentNodeId)/ancestor-or-self::Home//Resource

    /Chriztian

  • Garrett Fisher 341 posts 496 karma points
    Oct 17, 2012 @ 23:01
    Garrett Fisher
    0

    THAT'S IT!!!!!

    #BOOM.  Chriztian -- that's another feather in your cap and yet another gift basket I owe you.  I had TREID $currentPage although the particular picker I am using does NOT allow it.  So THANK YOU! 

    Both work exactly as I need.  Very much appreciated -- and timely :)

    Sincerely,
    Garrett

Please Sign in or register to post replies

Write your reply to:

Draft